From 1a1a4ddd190dfe905c3f8ec11d9e2a7e6a1c88e5 Mon Sep 17 00:00:00 2001 From: Ilya Bizyaev Date: Fri, 6 Dec 2024 23:24:00 +0100 Subject: [PATCH] =?UTF-8?q?Rename=20Limits::messages=5Fper=5Fmin=5Fchannel?= =?UTF-8?q?=20to=20=E2=80=A6=5Fchannel=5For=5Fsupergroup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Teloxide cannot distinguish supergroups from channels based on ChatIds, so channel throttling limits are applied to supergroups as well. It took me a while to troubleshoot why sending a bunch of messages was twice as slow as in the original Python implementation 😄 --- CHANGELOG.md | 1 + crates/teloxide-core/src/adaptors/throttle.rs | 2 +- crates/teloxide-core/src/adaptors/throttle/settings.rs | 6 +++--- crates/teloxide-core/src/adaptors/throttle/worker.rs | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 75e56d7a..81417feb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Some dependencies was bumped: `sqlx` to `0.8.1`, `tower` to `0.5.0`, `reqwest` to `0.12.7` - `tokio` version was explicitly specified as `1.39` - Added new `Send` and `Sync` trait bounds to the `UListener` and `Eh` generic parameters of `try_dispatch_with_listener` and `dispatch_with_listener` ([PR 1185](https://github.com/teloxide/teloxide/pull/1185)) [**BC**] +- Renamed `Limits::messages_per_min_channel` to `messages_per_min_channel_or_supergroup` to reflect its actual behavior ([PR 1214](https://github.com/teloxide/teloxide/pull/1214)) ### Fixed diff --git a/crates/teloxide-core/src/adaptors/throttle.rs b/crates/teloxide-core/src/adaptors/throttle.rs index 7c4aaba3..6d5eed88 100644 --- a/crates/teloxide-core/src/adaptors/throttle.rs +++ b/crates/teloxide-core/src/adaptors/throttle.rs @@ -185,7 +185,7 @@ enum ChatIdHash { } impl ChatIdHash { - fn is_channel(&self) -> bool { + fn is_channel_or_supergroup(&self) -> bool { match self { &Self::Id(id) => id.is_channel_or_supergroup(), Self::ChannelUsernameHash(_) => true, diff --git a/crates/teloxide-core/src/adaptors/throttle/settings.rs b/crates/teloxide-core/src/adaptors/throttle/settings.rs index 57b38e9a..9f66d5c2 100644 --- a/crates/teloxide-core/src/adaptors/throttle/settings.rs +++ b/crates/teloxide-core/src/adaptors/throttle/settings.rs @@ -47,8 +47,8 @@ pub struct Limits { /// Allowed messages in one chat per minute. pub messages_per_min_chat: u32, - /// Allowed messages in one channel per minute. - pub messages_per_min_channel: u32, + /// Allowed messages in one channel or supergroup per minute. + pub messages_per_min_channel_or_supergroup: u32, /// Allowed messages per second. pub messages_per_sec_overall: u32, @@ -104,7 +104,7 @@ impl Default for Limits { messages_per_sec_chat: 1, messages_per_sec_overall: 30, messages_per_min_chat: 20, - messages_per_min_channel: 10, + messages_per_min_channel_or_supergroup: 10, } } } diff --git a/crates/teloxide-core/src/adaptors/throttle/worker.rs b/crates/teloxide-core/src/adaptors/throttle/worker.rs index 26d08493..acb4d5ac 100644 --- a/crates/teloxide-core/src/adaptors/throttle/worker.rs +++ b/crates/teloxide-core/src/adaptors/throttle/worker.rs @@ -242,8 +242,8 @@ pub(super) async fn worker( 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 messages_per_min_limit = if chat.is_channel() { - limits.messages_per_min_channel + let messages_per_min_limit = if chat.is_channel_or_supergroup() { + limits.messages_per_min_channel_or_supergroup } else { limits.messages_per_min_chat };