update code level
This commit is contained in:
@@ -22,6 +22,8 @@ impl Database {
|
||||
cover_image_id: r.get("cover_image_id"),
|
||||
image_count: r.get("image_count"),
|
||||
created_at: r.get("created_at"),
|
||||
tags: vec![],
|
||||
persons: vec![],
|
||||
}
|
||||
}).collect())
|
||||
}
|
||||
@@ -114,6 +116,8 @@ impl Database {
|
||||
cover_image_id: r.get("cover_image_id"),
|
||||
image_count: r.get("image_count"),
|
||||
created_at: r.get("created_at"),
|
||||
tags: vec![],
|
||||
persons: vec![],
|
||||
}
|
||||
}).collect())
|
||||
}
|
||||
|
||||
@@ -45,6 +45,8 @@ impl Database {
|
||||
title: r.get("title"), document: r.get("document"),
|
||||
description: r.get("description"), cover_image_id: r.get("cover_image_id"),
|
||||
image_count: r.get("image_count"), created_at: r.get("created_at"),
|
||||
tags: vec![],
|
||||
persons: vec![],
|
||||
}).collect()
|
||||
}
|
||||
|
||||
@@ -182,6 +184,7 @@ impl Database {
|
||||
title: r.get("title"), document: r.get("document"),
|
||||
description: r.get("description"), cover_image_id: r.get("cover_image_id"),
|
||||
image_count: r.get("image_count"), created_at: r.get("created_at"),
|
||||
tags: vec![], persons: vec![],
|
||||
};
|
||||
map.entry(tag).or_default().push(album);
|
||||
}
|
||||
@@ -216,6 +219,7 @@ impl Database {
|
||||
title: r.get("title"), document: r.get("document"),
|
||||
description: r.get("description"), cover_image_id: r.get("cover_image_id"),
|
||||
image_count: r.get("image_count"), created_at: r.get("created_at"),
|
||||
tags: vec![], persons: vec![],
|
||||
}).collect()
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@ pub struct AlbumInfo {
|
||||
pub cover_image_id: Option<String>,
|
||||
pub image_count: i64,
|
||||
pub created_at: String,
|
||||
pub tags: Vec<String>,
|
||||
pub persons: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
|
||||
@@ -83,16 +83,40 @@ impl SearchDb {
|
||||
cover_image_id: r.get("cover_image_id"),
|
||||
image_count: r.get("image_count"),
|
||||
created_at: r.get("created_at"),
|
||||
tags: vec![],
|
||||
persons: vec![],
|
||||
}
|
||||
}).collect())
|
||||
}
|
||||
|
||||
/// 获取全量相册列表(缓存烘焙用)
|
||||
/// 获取全量相册列表(缓存烘焙用,含 tags 和 persons)
|
||||
pub async fn get_all_albums(&self) -> Result<Vec<AlbumInfo>, sqlx::Error> {
|
||||
let rows = sqlx::query(
|
||||
"SELECT id, title, cover_image_id, image_count, created_at FROM albums ORDER BY created_at DESC"
|
||||
).fetch_all(&self.pool).await?;
|
||||
|
||||
// 批量获取所有 album-tag 关系
|
||||
let tag_rows = sqlx::query(
|
||||
r#"SELECT at.album_id, t.name FROM album_tags at JOIN tags t ON at.tag_id = t.id"#
|
||||
).fetch_all(&self.pool).await?;
|
||||
let mut album_tags: std::collections::HashMap<String, Vec<String>> = std::collections::HashMap::new();
|
||||
for r in &tag_rows {
|
||||
let aid: String = r.get("album_id");
|
||||
let name: String = r.get("name");
|
||||
album_tags.entry(aid).or_default().push(name);
|
||||
}
|
||||
|
||||
// 批量获取所有 album-person 关系
|
||||
let person_rows = sqlx::query(
|
||||
r#"SELECT ap.album_id, p.name FROM album_persons ap JOIN persons p ON ap.person_id = p.id"#
|
||||
).fetch_all(&self.pool).await?;
|
||||
let mut album_persons: std::collections::HashMap<String, Vec<String>> = std::collections::HashMap::new();
|
||||
for r in &person_rows {
|
||||
let aid: String = r.get("album_id");
|
||||
let name: String = r.get("name");
|
||||
album_persons.entry(aid).or_default().push(name);
|
||||
}
|
||||
|
||||
Ok(rows.iter().map(|r| {
|
||||
let id_str: String = r.get("id");
|
||||
AlbumInfo {
|
||||
@@ -103,6 +127,8 @@ impl SearchDb {
|
||||
cover_image_id: r.get("cover_image_id"),
|
||||
image_count: r.get("image_count"),
|
||||
created_at: r.get("created_at"),
|
||||
tags: album_tags.remove(&id_str).unwrap_or_default(),
|
||||
persons: album_persons.remove(&id_str).unwrap_or_default(),
|
||||
}
|
||||
}).collect())
|
||||
}
|
||||
@@ -152,6 +178,8 @@ impl SearchDb {
|
||||
cover_image_id: r.get("cover_image_id"),
|
||||
image_count: r.get("image_count"),
|
||||
created_at: r.get("created_at"),
|
||||
tags: vec![],
|
||||
persons: vec![],
|
||||
};
|
||||
map.entry(tag_name).or_default().push(album);
|
||||
}
|
||||
@@ -179,6 +207,8 @@ impl SearchDb {
|
||||
cover_image_id: r.get("cover_image_id"),
|
||||
image_count: r.get("image_count"),
|
||||
created_at: r.get("created_at"),
|
||||
tags: vec![],
|
||||
persons: vec![],
|
||||
}
|
||||
}).collect()
|
||||
}
|
||||
@@ -294,6 +324,8 @@ impl SearchDb {
|
||||
cover_image_id: r.get("cover_image_id"),
|
||||
image_count: r.get("image_count"),
|
||||
created_at: r.get("created_at"),
|
||||
tags: vec![],
|
||||
persons: vec![],
|
||||
}
|
||||
}).collect()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user