feat: Identity JSON sync mechanism

- storage.rs: add local_profile field, check disk for profile.jpg in save_identity_file_by_pool
- tmdb_api.rs: trigger JSON sync after TMDb probe
- identity_api.rs: upload_profile_image triggers JSON sync
- identity_binding.rs: bind/unbind/merge trigger JSON sync
- get_identity_json: replace DB fallback with Lazy Sync (generates JSON from DB if missing)
- Fixes missing/obsolete JSON files for all identity mutations
This commit is contained in:
Accusys
2026-05-19 22:20:19 +08:00
parent 7680c202ef
commit 0eb08acaae
4 changed files with 129 additions and 54 deletions
+35 -12
View File
@@ -197,18 +197,41 @@ async fn tmdb_probe_handler(
}
match tmdb::probe::probe_from_cache(&state.db, &file_uuid).await {
Ok(result) => Ok(Json(TmdbProbeResponse {
success: true,
file_uuid,
tmdb_id: Some(result.tmdb_id),
movie_title: Some(result.title),
cast_count: Some(result.cast_count),
identities_created: Some(result.identities_created),
message: format!(
"Created/updated {} identities for movie ID {}",
result.identities_created, result.tmdb_id
),
})),
Ok(result) => {
// Sync identity JSON files for newly created/updated identities
let pool = state.db.pool().clone();
let file_uuid_clone = file_uuid.clone();
tokio::spawn(async move {
// Query identities linked to this file
let fi_table = crate::core::db::schema::table_name("file_identities");
let query = format!(
"SELECT i.uuid::text FROM {} fi JOIN {} i ON fi.identity_id = i.id WHERE fi.file_uuid = $1",
fi_table, crate::core::db::schema::table_name("identities")
);
if let Ok(rows) = sqlx::query_scalar::<_, String>(&query)
.bind(&file_uuid_clone)
.fetch_all(&pool)
.await
{
for uuid in rows {
let _ = crate::core::identity::storage::save_identity_file_by_pool(&pool, &uuid).await;
}
}
});
Ok(Json(TmdbProbeResponse {
success: true,
file_uuid,
tmdb_id: Some(result.tmdb_id),
movie_title: Some(result.title),
cast_count: Some(result.cast_count),
identities_created: Some(result.identities_created),
message: format!(
"Created/updated {} identities for movie ID {}",
result.identities_created, result.tmdb_id
),
}))
}
Err(e) => {
let msg = e.to_string();
if msg.contains("not found") {