update code level
This commit is contained in:
17
src/cache/mod.rs
vendored
17
src/cache/mod.rs
vendored
@@ -215,22 +215,23 @@ pub async fn refresh_all_caches(
|
||||
persons_cache: &Arc<RwLock<PersonCache>>,
|
||||
tags_cache: &Arc<RwLock<TagCache>>,
|
||||
) {
|
||||
// 1. 从主库读取相册(含 tags 和 persons 关联)
|
||||
// 1. 从主库读取相册(tags 和 persons 从 search.db 关联)
|
||||
if let Ok(albums) = db.get_all_albums().await {
|
||||
// 批量获取 album → tags 映射
|
||||
let tag_rows = sqlx::query("SELECT album_id, tag FROM album_tags")
|
||||
.fetch_all(&db.pool).await.unwrap_or_default();
|
||||
// 从 search.db 批量获取 album → tags 映射
|
||||
let tag_rows = sqlx::query(
|
||||
r#"SELECT at.album_id, t.name FROM album_tags at JOIN tags t ON at.tag_id = t.id"#
|
||||
).fetch_all(&search_db.pool).await.unwrap_or_default();
|
||||
let mut album_tags: std::collections::HashMap<String, Vec<String>> = std::collections::HashMap::new();
|
||||
for r in &tag_rows {
|
||||
let aid: String = r.get("album_id");
|
||||
let tag: String = r.get("tag");
|
||||
let tag: String = r.get("name");
|
||||
album_tags.entry(aid).or_default().push(tag);
|
||||
}
|
||||
|
||||
// 批量获取 album → persons 映射
|
||||
// 从 search.db 批量获取 album → persons 映射
|
||||
let person_rows = sqlx::query(
|
||||
r#"SELECT pa.album_id, p.name FROM person_albums pa JOIN persons p ON pa.person_id = p.id"#
|
||||
).fetch_all(&db.pool).await.unwrap_or_default();
|
||||
r#"SELECT ap.album_id, p.name FROM album_persons ap JOIN persons p ON ap.person_id = p.id"#
|
||||
).fetch_all(&search_db.pool).await.unwrap_or_default();
|
||||
let mut album_persons: std::collections::HashMap<String, Vec<String>> = std::collections::HashMap::new();
|
||||
for r in &person_rows {
|
||||
let aid: String = r.get("album_id");
|
||||
|
||||
Reference in New Issue
Block a user