mirror of
https://github.com/tiennm99/tiennm99bot.git
synced 2026-10-14 22:17:43 +00:00
fix(alias): answer inline queries from one store read under a deadline
Telegram expires an inline query and then rejects the answer with "query is too old and response timeout expired or query ID is invalid". The picker invited that: it listed the names and then read the store once per name — up to 50 round trips per keystroke — and it was the only handler in the module with no deadline of its own. Updates are dispatched one at a time, so a single slow answer also held up the queries queued behind it, each ageing while it waited, and one slow read expired a whole burst of typing. Add DocStore.Scan, which reads a key prefix with its values in one round trip, ordered by key. The picker and /aliases both use it, so neither grows a round trip per saved alias. Bound the inline handler at 3s: an answer later than that is rejected anyway, and giving up frees the worker for the fresher query behind it. When Telegram does reject an answer, the error now carries how long it took, which separates a slow handler from a query that was already stale on arrival. The 50-result cap now counts results the picker can show, so a video-note alias — which has no cached inline type — no longer consumes a slot.
This commit is contained in:
1 parent
cb86ec4cf3
commit
8260d2860b
9 files changed
+278
-63
No files matched your search
@@ -181,3 +181,25 @@ func TestInline_CapsAtFiftyResults(t *testing.T) {
|
||||
func uniqueName(i int) string {
|
||||
return "n" + strings.Repeat("x", i/10) + string(rune('a'+i%10))
|
||||
}
|
||||
|
||||
// The cap counts results the picker can actually show. A kind with no cached
|
||||
// inline type must not consume a slot, or a handful of video notes would
|
||||
// shrink an otherwise full answer.
|
||||
func TestInline_VideoNotesDoNotConsumeCapSlots(t *testing.T) {
|
||||
rb := installAlias(t)
|
||||
for i := 0; i < 10; i++ {
|
||||
rb.Bot.ProcessUpdate(context.Background(),
|
||||
aliasCmd(uniqueName(i), &models.Message{VideoNote: &models.VideoNote{FileID: "note-id"}}))
|
||||
}
|
||||
for i := 10; i < 70; i++ {
|
||||
rb.Bot.ProcessUpdate(context.Background(),
|
||||
aliasCmd(uniqueName(i), &models.Message{Text: "x"}))
|
||||
}
|
||||
|
||||
rb.Reset()
|
||||
rb.Bot.ProcessUpdate(context.Background(), inlineQuery(7, ""))
|
||||
|
||||
if got := len(inlineResults(t, rb)); got != 50 {
|
||||
t.Errorf("returned %d results, want the full 50 despite the skipped video notes", got)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user