From 4a80e3272f0471dd5b1b03b3a328b2b4da988fdc Mon Sep 17 00:00:00 2001 From: lychang <632945494@qq.com> Date: Tue, 21 Jul 2026 02:48:52 +0800 Subject: [PATCH] update code level --- src/cache/mod.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/cache/mod.rs b/src/cache/mod.rs index db6fe90..32535e6 100644 --- a/src/cache/mod.rs +++ b/src/cache/mod.rs @@ -262,8 +262,17 @@ pub async fn refresh_all_caches( c.update(enriched); } - // 3. 刷新人物(从 search.db) - let persons = search_db.get_all_persons_with_aliases().await; + // 3. 刷新人物(从 search.db,修正 total_albums/total_images) + let mut persons = search_db.get_all_persons_with_aliases().await; + // 从 album_persons 重新计算实际相册数(修复缓存中 total_albums 可能为 0 的问题) + for p in &mut persons { + let actual: i64 = sqlx::query_scalar( + "SELECT COUNT(*) FROM album_persons WHERE person_id = ?" + ).bind(p.id).fetch_one(&search_db.pool).await.unwrap_or(0); + if actual > 0 { + p.total_albums = actual; + } + } let mut pc = persons_cache.write().await; pc.update(persons); @@ -272,7 +281,15 @@ pub async fn refresh_all_caches( /// 仅刷新人物缓存(管线执行后调用) pub async fn refresh_persons_cache(search_db: &SearchDb, persons_cache: &Arc>) { - let persons = search_db.get_all_persons_with_aliases().await; + let mut persons = search_db.get_all_persons_with_aliases().await; + for p in &mut persons { + let actual: i64 = sqlx::query_scalar( + "SELECT COUNT(*) FROM album_persons WHERE person_id = ?" + ).bind(p.id).fetch_one(&search_db.pool).await.unwrap_or(0); + if actual > 0 { + p.total_albums = actual; + } + } let mut pc = persons_cache.write().await; pc.update(persons); }