Throttle: fix limit check
Previously both `messages_per_sec_chat` and `messages_per_min_chat` were
checked against last second message count.
@@ -465,9 +465,11 @@ async fn worker(
while let Some(entry) = queue_removing.next() {
let chat = &entry.value().0;
- let requests_sent_count = requests_sent.per_sec.get(chat).copied().unwrap_or(0);
- let limits_not_exceeded = requests_sent_count < limits.messages_per_sec_chat
- && requests_sent_count < limits.messages_per_min_chat;
+ let requests_sent_per_sec_count = requests_sent.per_sec.get(chat).copied().unwrap_or(0);
+ let requests_sent_per_min_count = requests_sent.per_min.get(chat).copied().unwrap_or(0);
+
+ let limits_not_exceeded = requests_sent_per_sec_count < limits.messages_per_sec_chat
+ && requests_sent_per_min_count < limits.messages_per_min_chat;
if limits_not_exceeded {
*requests_sent.per_sec.entry(*chat).or_insert(0) += 1;
