update code level

This commit is contained in:
lychang
2026-07-21 01:25:27 +08:00
parent 9d81c5077c
commit 90c493d41b
13 changed files with 93 additions and 61 deletions

View File

@@ -26,8 +26,8 @@ async fn main() -> std::io::Result<()> {
let args: Vec<String> = env::args().collect();
let export_to_search = args.iter().any(|a| a == "--export-search");
let search_db_cli_path = args.iter().find(|a| a.starts_with("--search-db="))
.map(|s| s.strip_prefix("--search-db=").unwrap_or("search.db"))
.unwrap_or("search.db");
.map(|s| s.strip_prefix("--search-db=").unwrap_or("search.db.bak"))
.unwrap_or("search.db.bak");
let clear_search = args.iter().any(|a| a == "--clear-search");
let wal_checkpoint = args.iter().any(|a| a == "--wal-checkpoint");
@@ -60,7 +60,7 @@ async fn main() -> std::io::Result<()> {
};
if export_to_search {
info!("[搜索导出] 开始将元数据导出到 search.db...");
info!("[搜索导出] 开始将元数据导出到 search.db.bak...");
match services::search_export::export_to_search_db(&db, search_db_cli_path, clear_search).await {
Ok(result) => {
info!("[搜索导出] 导出完成: 相册{}, 标签{}, 人物{}, 别名{}, 关联{}",
@@ -77,9 +77,9 @@ async fn main() -> std::io::Result<()> {
if wal_checkpoint {
info!("[WAL合并] 主数据库 WAL checkpoint 已在初始化时完成");
info!("[WAL合并] 正在合并 search.db WAL...");
let search_db = SearchDb::new("data/search.db").await
.expect("search.db 连接失败");
info!("[WAL合并] 正在合并 search.db.bak WAL...");
let search_db = SearchDb::new("data/search.db.bak").await
.expect("search.db.bak 连接失败");
search_db.wal_checkpoint().await;
info!("[WAL合并] 两个数据库均已合并完成");
std::process::exit(0);
@@ -87,16 +87,16 @@ async fn main() -> std::io::Result<()> {
let image_processor = Arc::new(image_processor::ImageProcessor::new(config.storage.clone()));
// ── 初始化 search.db(运行时搜索专用)──
let search_db_path = "data/search.db";
// ── 初始化 search.db.bak(运行时搜索专用)──
let search_db_path = "data/search.db.bak";
let search_db = Arc::new(
SearchDb::new(search_db_path).await
.expect("search.db 连接失败")
.expect("search.db.bak 连接失败")
);
info!("search.db 连接成功");
info!("search.db.bak 连接成功");
search_db.wal_checkpoint().await;
// ── 从 search.db 的 dict 表加载标签词典 ──
// ── 从 search.db.bak 的 dict 表加载标签词典 ──
match engine::tag_dict::reload_from_search_db(&search_db).await {
msg => info!("{}", msg),
}
@@ -129,25 +129,25 @@ async fn main() -> std::io::Result<()> {
let mut full_sync = false;
if new_count > 0 {
info!("[启动] 发现 {} 个新相册,增量同步到 search.db...", new_count);
info!("[启动] 发现 {} 个新相册,增量同步到 search.db.bak...", new_count);
let synced = engine::pipeline::sync_dirty_albums(&boot_db, &boot_search_db, &dirty).await;
info!("[启动] 增量同步完成:{} 个相册(解析在定时管线中执行)", synced);
} else {
info!("[启动] 没有新相册");
// 检查 search.db 是否为空(首次启动)
// 检查 search.db.bak 是否为空(首次启动)
let album_count: i64 = sqlx::query_scalar("SELECT COUNT(*) FROM albums")
.fetch_one(&boot_search_db.pool).await.unwrap_or(0);
if album_count == 0 {
info!("[启动] search.db 为空,执行全量同步...");
info!("[启动] search.db.bak 为空,执行全量同步...");
let synced = engine::pipeline::sync_albums_to_search_db(&boot_db, &boot_search_db).await;
info!("[启动] 全量同步完成:{} 个相册", synced);
full_sync = true;
}
}
// ③ 刷新所有内存缓存(从 search.db 读取)
// ③ 刷新所有内存缓存(从 search.db.bak 读取)
info!("[启动] ③ 刷新所有内存缓存...");
cache::refresh_all_caches(&boot_search_db, &boot_albums_cache, &boot_persons_cache, &boot_tags_cache).await;
cache::refresh_all_caches(&boot_db, &boot_search_db, &boot_albums_cache, &boot_persons_cache, &boot_tags_cache).await;
info!("[启动] 启动管线执行完毕(新相册={}, 全量同步={})", new_count, full_sync);
});
@@ -179,12 +179,12 @@ async fn main() -> std::io::Result<()> {
info!("[定时] 发现 {} 个新相册,增量解析...", new_albums.len());
engine::pipeline::phase_parse_dirty(&timer_db, &new_albums).await;
info!("[定时] 增量同步到 search.db...");
info!("[定时] 增量同步到 search.db.bak...");
engine::pipeline::sync_dirty_albums(&timer_db, &timer_search_db, &new_albums).await;
// ③ 刷新缓存
info!("[定时] 刷新缓存...");
cache::refresh_all_caches(&timer_search_db, &timer_cache, &timer_persons_cache, &timer_tags_cache).await;
cache::refresh_all_caches(&timer_db, &timer_search_db, &timer_cache, &timer_persons_cache, &timer_tags_cache).await;
}
});