From b9dd1f4d087c6e9db321aea914ce3e2a1435b6d1 Mon Sep 17 00:00:00 2001 From: YoursFunny Date: Mon, 21 Sep 2026 17:06:46 +0800 Subject: [PATCH] refactor(urls): fold the cache-hit caption branch into one call caption_from_fields already returns truncate_caption(built_in) for an empty format, which is exactly what the if-branch did; passing cached.caption as built_in makes both paths one call. The format path is unmoved -- built_in is read only when the format is empty. --- crates/xmedia-bot/src/handlers/urls.rs | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/crates/xmedia-bot/src/handlers/urls.rs b/crates/xmedia-bot/src/handlers/urls.rs index b9e2c16..ca81d0d 100644 --- a/crates/xmedia-bot/src/handlers/urls.rs +++ b/crates/xmedia-bot/src/handlers/urls.rs @@ -643,20 +643,18 @@ async fn url_media_inner( .get(site) .cloned() .unwrap_or_default(); - let caption = if format.is_empty() { - x_media::site::truncate_caption(&cached.caption) - } else { - x_media::site::caption_from_fields( - &format, - "", - &cached.url, - &cached.author, - &cached.author_url, - &cached.title, - &cached.content, - &cached.tags, - ) - }; + // One call for both: `caption_from_fields` returns the truncated + // built-in caption itself when the chat has no format for this site. + let caption = x_media::site::caption_from_fields( + &format, + &cached.caption, + &cached.url, + &cached.author, + &cached.author_url, + &cached.title, + &cached.content, + &cached.tags, + ); let items: Vec = cached .media .iter()