mirror of
https://github.com/TheFunny/TelegramTwitterMediaBot.git
synced 2026-10-08 01:42:05 +00:00
fix: let a successful send return a degraded entry to the fast path
Degrading a link-cache entry (previous commit) closed the "user retries right after a failure" case, but left a new one open: the entry could never regain file ids. `cache_sent_task` skipped *every* cached send — its rule was "the entry already holds the ids the next repeat wants" — which is true for a healthy entry and false for a degraded one. So a degraded entry (pixiv's hotlink-protected media, say) kept sending by URL forever, and every repeat paid a download and an upload through the fallback that the file ids would have avoided. Worse than the re-fetch it replaced. The rule is now the one it always meant: a send whose cache snapshot still carries file ids leaves the entry alone, and a send served from a degraded entry writes back the ids it produced (the URLs in the rewritten entry come from that send's own items, so they stay correct). Verified by a test that drives `cache_sent_task` directly with both task shapes: the degraded one updates the entry to the fresh id, the healthy one leaves it untouched. 125 bot tests + 91 x-media tests, live suite (14) pass. `cargo fmt --check`, `cargo clippy --workspace --all-targets --locked -- -D warnings` and `cargo test --workspace --locked` clean.
This commit is contained in:
@@ -15,13 +15,17 @@ use std::collections::HashMap;
|
||||
use std::sync::LazyLock;
|
||||
use teloxide::types::{ChatId, InlineKeyboardButton, InlineKeyboardMarkup, Message, MessageId};
|
||||
|
||||
/// Persists a successful send under the post's cache key. Only runs for a
|
||||
/// fresh (non-resumed) task that carried raw cache data with no file ids yet.
|
||||
/// Persists a successful send under the post's cache key. Skips a send that was
|
||||
/// served from the cache — its entry already holds the file ids the next repeat
|
||||
/// wants — *unless* the entry was degraded (no file ids left, see
|
||||
/// `invalidate_cache`): then the ids this send just produced are written back,
|
||||
/// which is what returns a degraded entry to the fast path instead of leaving
|
||||
/// it to re-upload the media on every repeat.
|
||||
pub(super) async fn cache_sent_task(ctx: &AppContext<'_>, task: &Task, media: Vec<CachedMedia>) {
|
||||
let Some(cache_data) = task.cache_data() else {
|
||||
return;
|
||||
};
|
||||
if !cache_data.media.is_empty() || media.is_empty() {
|
||||
if cache_data.media.iter().any(|m| !m.file_id.is_empty()) || media.is_empty() {
|
||||
return;
|
||||
}
|
||||
let mut post = cache_data.clone();
|
||||
|
||||
Reference in New Issue
Block a user