update code level

This commit is contained in:
lychang
2026-07-20 23:12:20 +08:00
parent 923f9bd7cf
commit 84409207e2
19 changed files with 1471 additions and 428 deletions

View File

@@ -1,5 +1,6 @@
use crate::cache::AlbumsCache;
use crate::db::Database;
use crate::search_db::SearchDb;
use crate::models::*;
use actix_web::{HttpResponse, Responder, web};
use std::collections::HashMap;
@@ -25,7 +26,7 @@ pub async fn get_albums(cache: web::Data<Arc<RwLock<AlbumsCache>>>) -> impl Resp
/// 规则:有任意过滤条件时 → 走 DB 懒加载(只查符合条件的相册)
/// 无过滤条件时 → 走缓存全量返回
pub async fn search_albums(
db: web::Data<Arc<Database>>,
search_db: web::Data<Arc<SearchDb>>,
cache: web::Data<Arc<RwLock<AlbumsCache>>>,
query: web::Query<HashMap<String, String>>,
) -> impl Responder {
@@ -50,7 +51,7 @@ pub async fn search_albums(
let person_arg = if person.is_empty() { None } else { Some(person) };
let q_arg = if q.is_empty() { None } else { Some(q) };
match db.search_albums_with_filters(tag_arg, person_arg, q_arg, limit, offset).await {
match search_db.search_albums(tag_arg, person_arg, q_arg, limit, offset).await {
Ok(results) => HttpResponse::Ok().json(results),
Err(e) => HttpResponse::InternalServerError().json(serde_json::json!({"error": format!("{}", e)})),
}