Merge pull request #40 from teloxide/remove_git_dep

Remove git dependency
This commit is contained in:
Temirkhan Myrzamadi 2021-01-22 09:17:25 +06:00 committed by GitHub
commit 592fadfa7d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 27 deletions

View file

@ -34,8 +34,7 @@ thiserror = "1.0.20"
once_cell = "1.5.0"
never = "0.1.0"
# FIXME(waffle): use crates.io once published
vecrem = { git = "https://github.com/WaffleLapkin/vecrem", rev = "6b9b6f42342df8b75548c6ed387072ff235429b1" }
vecrem = { version = "0.1", optional = true }
[features]
default = ["native-tls"]
@ -50,7 +49,7 @@ native-tls = ["reqwest/native-tls"]
nightly = []
# Throttling bot adaptor
throttle = []
throttle = ["vecrem"]
# CacheMe bot adaptor
cache_me = []

View file

@ -267,34 +267,33 @@ async fn worker(limits: Limits, mut queue_rx: mpsc::Receiver<(Id, Sender<Never>)
*hchats_s.entry(*chat).or_insert(0) += 1;
}
let mut queue_rem = queue.removing();
while let Some(entry) = queue_rem.next() {
let chat = &entry.value().0;
let cond = {
hchats_s.get(chat).copied().unwrap_or(0) < limits.chat_s
&& hchats.get(chat).copied().unwrap_or(0) < limits.chat_m
};
{
let mut queue_rem = queue.removing();
while let Some(entry) = queue_rem.next() {
let chat = &entry.value().0;
let cond = {
hchats_s.get(chat).copied().unwrap_or(0) < limits.chat_s
&& hchats.get(chat).copied().unwrap_or(0) < limits.chat_m
};
if cond {
{
*hchats_s.entry(*chat).or_insert(0) += 1;
*hchats.entry(*chat).or_insert(0) += 1;
history.push_back((*chat, Instant::now()));
if cond {
{
*hchats_s.entry(*chat).or_insert(0) += 1;
*hchats.entry(*chat).or_insert(0) += 1;
history.push_back((*chat, Instant::now()));
}
// This will close the channel unlocking associated request
drop(entry.remove());
// We've "sent" 1 request, so now we can send 1 less
allowed -= 1;
if allowed == 0 {
break;
}
}
// This will close the channel unlocking associated request
drop(entry.remove());
// We've "sent" 1 request, so now we can send 1 less
allowed -= 1;
if allowed == 0 {
break;
}
} else {
entry.skip();
}
}
drop(queue_rem);
// It's easier to just recompute last second stats, instead of keeping
// track of it alongside with minute stats, so we just throw this away.