update code level
This commit is contained in:
@@ -167,34 +167,25 @@ impl Database {
|
||||
}
|
||||
|
||||
pub async fn get_all_albums_full(&self) -> Vec<AlbumMeta> {
|
||||
let has_col = sqlx::query_scalar::<_, i64>(
|
||||
"SELECT COUNT(*) FROM pragma_table_info('albums') WHERE name = 'person_name_original'"
|
||||
).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
|
||||
r#"SELECT id, title, cover_image_id, image_count
|
||||
FROM albums"#
|
||||
).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"),
|
||||
cover_image_id: r.get("cover_image_id"),
|
||||
image_count: r.get("image_count"),
|
||||
}).collect()
|
||||
}
|
||||
|
||||
/// 按 ID 列表批量查询相册元数据(用于脏集增量解析,避免全表扫描)
|
||||
/// 按 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
|
||||
"SELECT id, title, cover_image_id, image_count
|
||||
FROM albums WHERE id IN ({})",
|
||||
placeholders.join(", ")
|
||||
);
|
||||
@@ -207,14 +198,19 @@ impl Database {
|
||||
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"),
|
||||
cover_image_id: r.get("cover_image_id"),
|
||||
image_count: r.get("image_count"),
|
||||
}).collect()
|
||||
}
|
||||
|
||||
/// 获取所有未处理的相册 ID(processed_at IS NULL),用于管线收集新相册
|
||||
pub async fn get_unprocessed_album_ids(&self) -> Vec<String> {
|
||||
let rows = sqlx::query_scalar::<_, String>(
|
||||
"SELECT id FROM albums WHERE processed_at IS NULL"
|
||||
).fetch_all(&self.pool).await.unwrap_or_default();
|
||||
rows
|
||||
}
|
||||
|
||||
// ── 写入 ──
|
||||
|
||||
pub async fn create_album(&self, album: CreateAlbum) -> Result<Uuid, sqlx::Error> {
|
||||
|
||||
Reference in New Issue
Block a user