update code level
This commit is contained in:
16
src/cache/mod.rs
vendored
16
src/cache/mod.rs
vendored
@@ -1,6 +1,6 @@
|
||||
//! 缓存层 — 内存缓存管理
|
||||
|
||||
use crate::db::Database;
|
||||
use crate::search_db::SearchDb;
|
||||
use crate::models::*;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
@@ -206,25 +206,25 @@ impl PersonCache {
|
||||
|
||||
/// 刷新所有缓存(相册 + 标签 + 人物)
|
||||
pub async fn refresh_all_caches(
|
||||
db: &Database,
|
||||
search_db: &SearchDb,
|
||||
albums_cache: &Arc<RwLock<AlbumsCache>>,
|
||||
persons_cache: &Arc<RwLock<PersonCache>>,
|
||||
tags_cache: &Arc<RwLock<TagCache>>,
|
||||
) {
|
||||
// 1. 刷新相册
|
||||
if let Ok(albums) = db.get_all_albums().await {
|
||||
if let Ok(albums) = search_db.get_all_albums().await {
|
||||
let mut c = albums_cache.write().await;
|
||||
c.update(albums.clone());
|
||||
|
||||
// 2. 刷新标签
|
||||
let popular_tags = db.get_popular_tags(200).await;
|
||||
let tag_albums = db.get_all_tag_albums().await;
|
||||
let popular_tags = search_db.get_popular_tags(200).await;
|
||||
let tag_albums = search_db.get_all_tag_albums().await;
|
||||
let mut tc = tags_cache.write().await;
|
||||
tc.update(popular_tags, tag_albums);
|
||||
}
|
||||
|
||||
// 3. 刷新人物
|
||||
let persons = db.get_all_persons_with_aliases().await;
|
||||
let persons = search_db.get_all_persons_with_aliases().await;
|
||||
let mut pc = persons_cache.write().await;
|
||||
pc.update(persons);
|
||||
|
||||
@@ -232,8 +232,8 @@ pub async fn refresh_all_caches(
|
||||
}
|
||||
|
||||
/// 仅刷新人物缓存(管线执行后调用)
|
||||
pub async fn refresh_persons_cache(db: &Database, persons_cache: &Arc<RwLock<PersonCache>>) {
|
||||
let persons = db.get_all_persons_with_aliases().await;
|
||||
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 pc = persons_cache.write().await;
|
||||
pc.update(persons);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user