update code level
This commit is contained in:
@@ -172,9 +172,10 @@ impl Database {
|
||||
).fetch_one(&self.pool).await.unwrap_or(0);
|
||||
if has_col == 0 { return Vec::new(); }
|
||||
|
||||
// 去掉 ORDER BY:管线处理不需要排序,省去排序开销
|
||||
let rows = sqlx::query(
|
||||
r#"SELECT id, title, person_name_original, person_name_cleaned, tags, all_words, raw_title, processed_at, image_count
|
||||
FROM albums ORDER BY created_at DESC"#
|
||||
FROM albums"#
|
||||
).fetch_all(&self.pool).await.unwrap_or_default();
|
||||
|
||||
rows.iter().map(|r| AlbumMeta {
|
||||
@@ -187,6 +188,33 @@ impl Database {
|
||||
}).collect()
|
||||
}
|
||||
|
||||
/// 按 ID 列表批量查询相册元数据(用于脏集增量解析,避免全表扫描)
|
||||
pub async fn get_albums_by_ids(&self, ids: &[String]) -> Vec<AlbumMeta> {
|
||||
if ids.is_empty() { return Vec::new(); }
|
||||
|
||||
let placeholders: Vec<String> = (0..ids.len()).map(|_| "?".to_string()).collect();
|
||||
let sql = format!(
|
||||
"SELECT id, title, person_name_original, person_name_cleaned, tags, all_words, raw_title, processed_at, image_count
|
||||
FROM albums WHERE id IN ({})",
|
||||
placeholders.join(", ")
|
||||
);
|
||||
|
||||
let mut query = sqlx::query(&sql);
|
||||
for id in ids {
|
||||
query = query.bind(id);
|
||||
}
|
||||
|
||||
let rows = query.fetch_all(&self.pool).await.unwrap_or_default();
|
||||
rows.iter().map(|r| AlbumMeta {
|
||||
id: r.get("id"), title: r.get("title"),
|
||||
person_name_original: r.get("person_name_original"),
|
||||
person_name_cleaned: r.get("person_name_cleaned"),
|
||||
tags: r.get("tags"), all_words: r.get("all_words"),
|
||||
raw_title: r.get("raw_title"), processed_at: r.get("processed_at"),
|
||||
image_count: r.get("image_count"),
|
||||
}).collect()
|
||||
}
|
||||
|
||||
// ── 写入 ──
|
||||
|
||||
pub async fn create_album(&self, album: CreateAlbum) -> Result<Uuid, sqlx::Error> {
|
||||
|
||||
Reference in New Issue
Block a user