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.
This commit is contained in:
2026-09-21 17:06:46 +08:00
parent 9aed6f4a24
commit b9dd1f4d08
+12 -14
View File
@@ -643,20 +643,18 @@ async fn url_media_inner(
.get(site) .get(site)
.cloned() .cloned()
.unwrap_or_default(); .unwrap_or_default();
let caption = if format.is_empty() { // One call for both: `caption_from_fields` returns the truncated
x_media::site::truncate_caption(&cached.caption) // built-in caption itself when the chat has no format for this site.
} else { let caption = x_media::site::caption_from_fields(
x_media::site::caption_from_fields( &format,
&format, &cached.caption,
"", &cached.url,
&cached.url, &cached.author,
&cached.author, &cached.author_url,
&cached.author_url, &cached.title,
&cached.title, &cached.content,
&cached.content, &cached.tags,
&cached.tags, );
)
};
let items: Vec<MediaItemPayload> = cached let items: Vec<MediaItemPayload> = cached
.media .media
.iter() .iter()