update code level
This commit is contained in:
51
src/main.rs
51
src/main.rs
@@ -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.bak"))
|
||||
.unwrap_or("search.db.bak");
|
||||
.map(|s| s.strip_prefix("--search-db=").unwrap_or("search.db"))
|
||||
.unwrap_or("search.db");
|
||||
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.bak...");
|
||||
info!("[搜索导出] 开始将元数据导出到 search.db...");
|
||||
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.bak WAL...");
|
||||
let search_db = SearchDb::new("data/search.db.bak").await
|
||||
.expect("search.db.bak 连接失败");
|
||||
info!("[WAL合并] 正在合并 search.db WAL...");
|
||||
let search_db = SearchDb::new("data/search.db").await
|
||||
.expect("search.db 连接失败");
|
||||
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.bak(运行时搜索专用)──
|
||||
let search_db_path = "data/search.db.bak";
|
||||
// ── 初始化 search.db(运行时搜索专用)──
|
||||
let search_db_path = "data/search.db";
|
||||
let search_db = Arc::new(
|
||||
SearchDb::new(search_db_path).await
|
||||
.expect("search.db.bak 连接失败")
|
||||
.expect("search.db 连接失败")
|
||||
);
|
||||
info!("search.db.bak 连接成功");
|
||||
info!("search.db 连接成功");
|
||||
search_db.wal_checkpoint().await;
|
||||
|
||||
// ── 从 search.db.bak 的 dict 表加载标签词典 ──
|
||||
// ── 从 search.db 的 dict 表加载标签词典 ──
|
||||
match engine::tag_dict::reload_from_search_db(&search_db).await {
|
||||
msg => info!("{}", msg),
|
||||
}
|
||||
@@ -126,29 +126,18 @@ async fn main() -> std::io::Result<()> {
|
||||
info!("[启动] ② 查找新相册...");
|
||||
let dirty = engine::pipeline::phase_collect_new_albums(&boot_db).await;
|
||||
let new_count = dirty.len();
|
||||
let mut full_sync = false;
|
||||
|
||||
if new_count > 0 {
|
||||
info!("[启动] 发现 {} 个新相册,增量同步到 search.db.bak...", new_count);
|
||||
info!("[启动] 发现 {} 个新相册,同步到 search.db...", new_count);
|
||||
let synced = engine::pipeline::sync_dirty_albums(&boot_db, &boot_search_db, &dirty).await;
|
||||
info!("[启动] 增量同步完成:{} 个相册(解析在定时管线中执行)", synced);
|
||||
info!("[启动] 增量同步完成:{} 个相册(仅 tags/persons)", synced);
|
||||
} else {
|
||||
info!("[启动] 没有新相册");
|
||||
// 检查 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.bak 为空,执行全量同步...");
|
||||
let synced = engine::pipeline::sync_albums_to_search_db(&boot_db, &boot_search_db).await;
|
||||
info!("[启动] 全量同步完成:{} 个相册", synced);
|
||||
full_sync = true;
|
||||
}
|
||||
}
|
||||
|
||||
// ③ 刷新所有内存缓存(从 search.db.bak 读取)
|
||||
// ③ 刷新所有内存缓存(从 search.db 读取)
|
||||
info!("[启动] ③ 刷新所有内存缓存...");
|
||||
cache::refresh_all_caches(&boot_db, &boot_search_db, &boot_albums_cache, &boot_persons_cache, &boot_tags_cache).await;
|
||||
info!("[启动] 启动管线执行完毕(新相册={}, 全量同步={})", new_count, full_sync);
|
||||
info!("[启动] 启动管线执行完毕(新相册={})", new_count);
|
||||
});
|
||||
|
||||
// ── 定时管线(每 30 分钟):导入 → 增量解析 → 缓存刷新 ──
|
||||
@@ -171,15 +160,15 @@ async fn main() -> std::io::Result<()> {
|
||||
}
|
||||
|
||||
// ② 查找新相册
|
||||
let new_albums = engine::pipeline::phase_collect_new_albums(&timer_db).await;
|
||||
if new_albums.is_empty() {
|
||||
continue; // 无新增,跳过
|
||||
}
|
||||
let new_albums = engine::pipeline::phase_collect_new_albums(&timer_db).await;
|
||||
if new_albums.is_empty() {
|
||||
continue; // 无新增,跳过
|
||||
}
|
||||
|
||||
info!("[定时] 发现 {} 个新相册,增量解析...", new_albums.len());
|
||||
engine::pipeline::phase_parse_dirty(&timer_db, &new_albums).await;
|
||||
|
||||
info!("[定时] 增量同步到 search.db.bak...");
|
||||
info!("[定时] 同步到 search.db...");
|
||||
engine::pipeline::sync_dirty_albums(&timer_db, &timer_search_db, &new_albums).await;
|
||||
|
||||
// ③ 刷新缓存
|
||||
|
||||
Reference in New Issue
Block a user