update code level
This commit is contained in:
@@ -6,17 +6,16 @@ use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
/// GET /api/people — 从缓存获取所有人名列表
|
||||
/// GET /api/people — 从内存缓存获取所有人名列表
|
||||
pub async fn get_people(cache: web::Data<Arc<RwLock<PersonCache>>>) -> impl Responder {
|
||||
let c = cache.read().await;
|
||||
// 缓存中已按 total_albums DESC 排序
|
||||
HttpResponse::Ok().json(PersonListResponse {
|
||||
total: c.persons.len(),
|
||||
persons: c.persons.clone(),
|
||||
})
|
||||
}
|
||||
|
||||
/// GET /api/people/search?q=关键词 — 从缓存搜索人名
|
||||
/// GET /api/people/search?q=关键词 — 从内存缓存搜索人名
|
||||
pub async fn search_people(
|
||||
cache: web::Data<Arc<RwLock<PersonCache>>>,
|
||||
query: web::Query<HashMap<String, String>>,
|
||||
@@ -36,7 +35,7 @@ pub async fn search_people(
|
||||
})
|
||||
}
|
||||
|
||||
/// GET /api/people/{name} — 从缓存查找人物详情(相册列表从 search.db)
|
||||
/// GET /api/people/{name} — 从 search.db 查找人物详情(缓存查人物信息,search.db 查相册列表)
|
||||
pub async fn get_person_detail(
|
||||
search_db: web::Data<Arc<SearchDb>>,
|
||||
cache: web::Data<Arc<RwLock<PersonCache>>>,
|
||||
@@ -44,7 +43,7 @@ pub async fn get_person_detail(
|
||||
) -> impl Responder {
|
||||
let name = path.into_inner();
|
||||
let c = cache.read().await;
|
||||
// 在缓存中搜索
|
||||
// 在内存缓存中查找人物
|
||||
let found = c.search(&name);
|
||||
let p = found.into_iter().find(|p| p.name.to_lowercase() == name.to_lowercase());
|
||||
match p {
|
||||
|
||||
Reference in New Issue
Block a user