update code level

This commit is contained in:
lychang
2026-05-14 00:04:35 +08:00
parent 8f214b587b
commit 73dbb30e27
7 changed files with 128 additions and 4541 deletions

View File

@@ -46,37 +46,17 @@ async fn main() -> std::io::Result<()> {
let image_processor = Arc::new(image_processor::ImageProcessor::new(config.storage.clone()));
// 初始化智能任务队列
let task_queue = Arc::new(queue::TaskQueue::new_with_db(
config.queue.max_concurrent_tasks, // 最大并发任务数
config.queue.queue_size_limit, // 队列大小限制
config.queue.high_request_rate_threshold, // 高请求频率阈值
config.queue.idle_request_rate_threshold, // 空闲请求频率阈值
Arc::clone(&db), // 数据库实例
));
// 在后台线程中自动导入新相册(不阻塞HTTP服务启动)
let config_clone = config.clone();
let db_clone = Arc::clone(&db);
let task_queue_clone = Arc::clone(&task_queue);
tokio::spawn(async move {
info!("[后台任务] 开始扫描图片目录并导入新相册...");
match import::import_existing_data(&config_clone, db_clone, Some(task_queue_clone)).await {
match import::import_existing_data(&config_clone, db_clone, None).await {
Ok(_) => info!("[后台任务] 相册导入完成"),
Err(e) => error!("[后台任务] 相册导入失败: {}", e),
}
});
// 启动相册导入Worker
let album_import_worker = queue::AlbumImportWorker::new(
Arc::clone(&task_queue),
Arc::clone(&db),
config.storage.clone(),
);
tokio::spawn(async move {
album_import_worker.start().await;
});
// 初始化相册内存缓存
let albums_cache = Arc::new(tokio::sync::RwLock::new(AlbumsCache::new()));
@@ -118,11 +98,7 @@ async fn main() -> std::io::Result<()> {
}
});
// 启动定时清理过期任务的任务(每小时执行一次)
let task_queue_for_cleanup = Arc::clone(&task_queue);
tokio::spawn(async move {
task_queue_for_cleanup.start_periodic_cleanup(Duration::from_secs(60 * 60)).await; // 1小时
});
println!("API接口:");
println!(" - GET /api/albums - 获取所有相册");
@@ -152,7 +128,6 @@ async fn main() -> std::io::Result<()> {
.app_data(web::Data::new(Arc::clone(&db)))
.app_data(web::Data::new(Arc::clone(&image_processor)))
.app_data(web::Data::new(Arc::clone(&albums_cache)))
// 不再需要任务队列作为app_data,因为已移除缩略图功能
// API路由
.route("/api/albums", web::get().to(routes::get_albums))
.route("/api/search", web::get().to(routes::search_albums))