update code level

This commit is contained in:
lychang
2026-07-21 02:48:52 +08:00
parent 992ee32e9b
commit 4a80e3272f

23
src/cache/mod.rs vendored
View File

@@ -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<RwLock<PersonCache>>) {
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);
}