Rename Limits::messages_per_min_channel to …_channel_or_supergroup

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 😄
This commit is contained in:
Ilya Bizyaev 2024-12-06 23:24:00 +01:00
parent 94db1757dc
commit 1a1a4ddd19
No known key found for this signature in database
GPG key ID: 29AACC9F9F66C5B4
4 changed files with 7 additions and 6 deletions

View file

@ -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` - 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` - `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**] - 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 ### Fixed

View file

@ -185,7 +185,7 @@ enum ChatIdHash {
} }
impl ChatIdHash { impl ChatIdHash {
fn is_channel(&self) -> bool { fn is_channel_or_supergroup(&self) -> bool {
match self { match self {
&Self::Id(id) => id.is_channel_or_supergroup(), &Self::Id(id) => id.is_channel_or_supergroup(),
Self::ChannelUsernameHash(_) => true, Self::ChannelUsernameHash(_) => true,

View file

@ -47,8 +47,8 @@ pub struct Limits {
/// Allowed messages in one chat per minute. /// Allowed messages in one chat per minute.
pub messages_per_min_chat: u32, pub messages_per_min_chat: u32,
/// Allowed messages in one channel per minute. /// Allowed messages in one channel or supergroup per minute.
pub messages_per_min_channel: u32, pub messages_per_min_channel_or_supergroup: u32,
/// Allowed messages per second. /// Allowed messages per second.
pub messages_per_sec_overall: u32, pub messages_per_sec_overall: u32,
@ -104,7 +104,7 @@ impl Default for Limits {
messages_per_sec_chat: 1, messages_per_sec_chat: 1,
messages_per_sec_overall: 30, messages_per_sec_overall: 30,
messages_per_min_chat: 20, messages_per_min_chat: 20,
messages_per_min_channel: 10, messages_per_min_channel_or_supergroup: 10,
} }
} }
} }

View file

@ -242,8 +242,8 @@ pub(super) async fn worker<B>(
let requests_sent_per_sec_count = requests_sent.per_sec.get(chat).copied().unwrap_or(0); 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 requests_sent_per_min_count = requests_sent.per_min.get(chat).copied().unwrap_or(0);
let messages_per_min_limit = if chat.is_channel() { let messages_per_min_limit = if chat.is_channel_or_supergroup() {
limits.messages_per_min_channel limits.messages_per_min_channel_or_supergroup
} else { } else {
limits.messages_per_min_chat limits.messages_per_min_chat
}; };