update code level
This commit is contained in:
@@ -138,8 +138,6 @@ impl Database {
|
||||
image_count: row.get("image_count"),
|
||||
created_at: row.get("created_at"),
|
||||
updated_at: row.get("updated_at"),
|
||||
person_name_cleaned: row.get("person_name_cleaned"),
|
||||
tags: row.get("tags"),
|
||||
};
|
||||
|
||||
let img_rows = sqlx::query("SELECT * FROM images WHERE album_id = ?")
|
||||
|
||||
@@ -28,11 +28,11 @@ impl Database {
|
||||
let person_name = result.person_name.as_deref();
|
||||
|
||||
if let Some(name) = person_name {
|
||||
// ── update 相册 person 字段 ──
|
||||
// ── 标记处理时间(person_name 列已迁移到 search.db)──
|
||||
sqlx::query(
|
||||
"UPDATE albums SET person_name_original = ?, person_name_cleaned = ?, processed_at = datetime('now') WHERE id = ?"
|
||||
"UPDATE albums SET processed_at = datetime('now') WHERE id = ?"
|
||||
)
|
||||
.bind(name).bind(name).bind(album_id)
|
||||
.bind(album_id)
|
||||
.execute(&mut **tx).await?;
|
||||
|
||||
// ── insert or ignore 人物 ──
|
||||
@@ -60,23 +60,8 @@ impl Database {
|
||||
.execute(&mut **tx).await?;
|
||||
}
|
||||
|
||||
// ── 写标签 ──
|
||||
// ── 写标签(tags/all_words 列已迁移到 search.db,只维护 album_tags 表)──
|
||||
if !result.tags.is_empty() {
|
||||
let tags_json = serde_json::to_string(
|
||||
&result.tags.iter().map(|(t, _)| t).collect::<Vec<_>>()
|
||||
).unwrap_or_else(|_| "[]".to_string());
|
||||
let all_words: Vec<[String; 2]> = result.tags.iter()
|
||||
.map(|(t, c)| [t.clone(), c.clone()])
|
||||
.collect();
|
||||
let words_json = serde_json::to_string(&all_words).unwrap_or_else(|_| "[]".to_string());
|
||||
|
||||
sqlx::query(
|
||||
"UPDATE albums SET tags = ?, all_words = ? WHERE id = ?"
|
||||
)
|
||||
.bind(&tags_json).bind(&words_json).bind(album_id)
|
||||
.execute(&mut **tx).await?;
|
||||
|
||||
// ── 同步 album_tags 表 ──
|
||||
sqlx::query("DELETE FROM album_tags WHERE album_id = ?")
|
||||
.bind(album_id).execute(&mut **tx).await?;
|
||||
for (t, _) in &result.tags {
|
||||
|
||||
@@ -364,27 +364,26 @@ impl Database {
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn update_album_person(&self, album_id: &str, person_name_original: &str, person_name_cleaned: &str) {
|
||||
sqlx::query("UPDATE albums SET person_name_original = ?, person_name_cleaned = ?, processed_at = datetime('now') WHERE id = ?")
|
||||
.bind(person_name_original).bind(person_name_cleaned).bind(album_id).execute(&self.pool).await.ok();
|
||||
pub async fn update_album_person(&self, album_id: &str, _person_name_original: &str, _person_name_cleaned: &str) {
|
||||
sqlx::query("UPDATE albums SET processed_at = datetime('now') WHERE id = ?")
|
||||
.bind(album_id).execute(&self.pool).await.ok();
|
||||
}
|
||||
|
||||
pub async fn update_album_person_with_tx(&self, tx: &mut Transaction<'_, Sqlite>, album_id: &str, person_name_original: &str, person_name_cleaned: &str) {
|
||||
sqlx::query("UPDATE albums SET person_name_original = ?, person_name_cleaned = ?, processed_at = datetime('now') WHERE id = ?")
|
||||
.bind(person_name_original).bind(person_name_cleaned).bind(album_id).execute(tx.deref_mut()).await.ok();
|
||||
pub async fn update_album_person_with_tx(&self, tx: &mut Transaction<'_, Sqlite>, album_id: &str, _person_name_original: &str, _person_name_cleaned: &str) {
|
||||
sqlx::query("UPDATE albums SET processed_at = datetime('now') WHERE id = ?")
|
||||
.bind(album_id).execute(tx.deref_mut()).await.ok();
|
||||
}
|
||||
|
||||
/// 清空该人物所有关联相册的 person 字段(当该人物被确认为非人物后调用)
|
||||
pub async fn update_album_person_by_person_id(&self, person_id: i64) {
|
||||
sqlx::query(
|
||||
"UPDATE albums SET person_name_original = NULL, person_name_cleaned = NULL, \
|
||||
processed_at = datetime('now') WHERE id IN (SELECT album_id FROM person_albums WHERE person_id = ?)"
|
||||
"UPDATE albums SET processed_at = datetime('now') WHERE id IN (SELECT album_id FROM person_albums WHERE person_id = ?)"
|
||||
).bind(person_id).execute(&self.pool).await.ok();
|
||||
}
|
||||
|
||||
pub async fn update_album_tags(&self, album_id: &str, tags_json: &str, all_words_json: &str) {
|
||||
sqlx::query("UPDATE albums SET tags = ?, all_words = ?, processed_at = datetime('now') WHERE id = ?")
|
||||
.bind(tags_json).bind(all_words_json).bind(album_id).execute(&self.pool).await.ok();
|
||||
pub async fn update_album_tags(&self, album_id: &str, tags_json: &str, _all_words_json: &str) {
|
||||
sqlx::query("UPDATE albums SET processed_at = datetime('now') WHERE id = ?")
|
||||
.bind(album_id).execute(&self.pool).await.ok();
|
||||
|
||||
// 用一个事务批量替换 album_tags,避免逐条 autocommit 导致巨慢
|
||||
if let Ok(tags) = serde_json::from_str::<Vec<String>>(tags_json) {
|
||||
@@ -418,9 +417,9 @@ impl Database {
|
||||
}
|
||||
|
||||
/// 与 update_album_tags 相同,但使用已有的事务(不启动内部子事务)
|
||||
pub async fn update_album_tags_with_tx(&self, tx: &mut Transaction<'_, Sqlite>, album_id: &str, tags_json: &str, all_words_json: &str) {
|
||||
sqlx::query("UPDATE albums SET tags = ?, all_words = ?, processed_at = datetime('now') WHERE id = ?")
|
||||
.bind(tags_json).bind(all_words_json).bind(album_id).execute(tx.deref_mut()).await.ok();
|
||||
pub async fn update_album_tags_with_tx(&self, tx: &mut Transaction<'_, Sqlite>, album_id: &str, tags_json: &str, _all_words_json: &str) {
|
||||
sqlx::query("UPDATE albums SET processed_at = datetime('now') WHERE id = ?")
|
||||
.bind(album_id).execute(tx.deref_mut()).await.ok();
|
||||
|
||||
sqlx::query("DELETE FROM album_tags WHERE album_id = ?")
|
||||
.bind(album_id)
|
||||
|
||||
@@ -10,10 +10,6 @@ pub struct Album {
|
||||
pub image_count: i64,
|
||||
pub created_at: String,
|
||||
pub updated_at: String,
|
||||
#[serde(default)]
|
||||
pub person_name_cleaned: Option<String>,
|
||||
#[serde(default)]
|
||||
pub tags: Option<String>, // JSON: [tag, ...]
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
|
||||
Reference in New Issue
Block a user