mirror of
https://github.com/TheFunny/TelegramTwitterMediaBot.git
synced 2026-09-23 23:32:05 +00:00
Two calls per link went out that could not affect anything: - `run_with_chat_action` awaited the opening `send_chat_action` to completion before the pipeline was polled at all, and again inside the loop on every `ACTION_REFRESH`. Telegram round trips are hundreds of ms: the first delay came out of the user's wait for every link, and each refresh suspended the fetch (an ugoira encode or HLS remux runs for seconds) by the same amount. - `handle_message` enqueued *every* URL a private chat posted, including links no site adapter claims. Those cost a queue slot, a worker wake-up, a `Message` clone and (through the action above) one Telegram call, only for `url_media_inner` to conclude there was nothing to send. The group branch has always made the `cache_key(url).is_some()` test before it acts; the private branch now makes it before it enqueues. The in-flight action is held (`Option<BoxFuture>` — the sender surface is already type-erased, so it is `Unpin`) and polled as its own `select!` branch: still polled *before* the pipeline, so the indicator is on screen before the first send, but a slow Telegram response can no longer delay the pipeline, and none of the branch bodies ever awaits one. One action is in flight at a time; a refresh while one is unanswered is skipped rather than dropping the request mid-flight. Note that `select!` evaluates every branch's future expression eagerly, so the `None` case is an `async` block whose `unwrap` only runs when the branch is polled (the eager form panicked). Behavior pinned by the existing tests, unchanged: the opening action precedes the first send, a 12s pipeline still sees exactly three actions (`a_long_pipeline_keeps_the_chat_action_alive`), and an unsupported URL reaching `url_media` still gets the one indicator before the pipeline settles — in production it no longer reaches `url_media` at all. `cargo fmt --check`, `cargo clippy --workspace --all-targets --locked -- -D warnings` and `cargo test --workspace --locked` clean.