fix(chats,drafts): batch getDialogs requests instead of one RPC per dialog#250
Open
yagop wants to merge 1 commit into
Open
fix(chats,drafts): batch getDialogs requests instead of one RPC per dialog#250yagop wants to merge 1 commit into
yagop wants to merge 1 commit into
Conversation
…ialog The dialogs iterator's default batch size is 1, so it issued one messages.getDialogs RPC per dialog. `tg chats list` was slow (one round trip per chat up to --limit) and `tg drafts` was worse: it scans every dialog in the account with no limit, so it walked the whole list one RPC at a time. Set BatchSize: min(limit, 100) for chats (respecting --limit) and a flat 100 for drafts (full scan, no user limit). Telegram does not reject a per-request limit above 100 but silently returns fewer/incorrect results, so 100 is the safe maximum. chats clamps to at least 1, since a non-positive batch size panics the iterator (it preallocates a slice with that capacity) and a negative --limit would otherwise crash the process. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
tg chats listandtg draftsare slow for the same reason as #249, in a different command: the gotd dialogs iterator is created without a batch size, leaving the builder's default of 1. It therefore issues onemessages.getDialogsRPC per dialog.tg chats list— one round trip per chat, up to--limit(default 100).tg drafts— worse:listDraftsscans every dialog in the account with no limit to find the ones with a draft, so it walks the whole list one round trip at a time.Fix
Set
BatchSizeon the builder:max(1, min(limit, 100)), respecting--limit.100(full scan, no user-facing limit).Cap at 100 — Telegram does not reject a per-request limit above 100 but silently returns fewer/incorrect results (see gotd's own
BatchSizedoc; verified empirically againstmessages.getHistory— requesting 150/200 returns exactly 100), so 100 is the safe maximum. Clamp to ≥ 1 (chats) — a non-positive batch size panics the iterator (NewIteratorpreallocates a slice with that capacity), so a negative--limitwould otherwise crash the process.Tests
TestListChatsBatchSize— asserts the per-request limit sent is5/100/100for--limit 5/100/350and clamps to1for0/-1(no panic).TestListDraftsBatchSize— asserts the dialog scan requests 100 per RPC.Companion to #249 (same class of bug;
GetHistorythere,GetDialogshere).🤖 Generated with Claude Code