fix: add trace_profiles deletion to unregister
trace_profiles was missing from the unregister cleanup, leaving orphaned records when files were unregistered. This caused data inconsistency: - trace_profiles remained while Qdrant _faces and TKG nodes were deleted - Studio could show stale face groups pointing to non-existent data Changes: - Added trace_profiles_table to both unregister functions - Added delete_safe! call to delete trace_profiles by file_uuid - Updated log message to include trace_profiles count Verified: Cleaned up 24 orphaned records for a4442006be2d401a7e22ed8ff29da772
This commit is contained in:
+25
-4
@@ -1114,7 +1114,11 @@ async fn unregister(
|
||||
None => return Err(StatusCode::BAD_REQUEST),
|
||||
};
|
||||
|
||||
tracing::info!("[UNREGISTER] Unregistering file: {} (async_mode={})", uuid, req.async_mode);
|
||||
tracing::info!(
|
||||
"[UNREGISTER] Unregistering file: {} (async_mode={})",
|
||||
uuid,
|
||||
req.async_mode
|
||||
);
|
||||
|
||||
// Async mode: spawn background task and return immediately
|
||||
if req.async_mode {
|
||||
@@ -1122,7 +1126,10 @@ async fn unregister(
|
||||
let state_clone = state.clone();
|
||||
let uuid_clone = uuid.clone();
|
||||
tokio::spawn(async move {
|
||||
tracing::info!("[ASYNC_UNREGISTER] Starting background unregister for {}", uuid_clone);
|
||||
tracing::info!(
|
||||
"[ASYNC_UNREGISTER] Starting background unregister for {}",
|
||||
uuid_clone
|
||||
);
|
||||
match unregister_internal(&state_clone, &uuid_clone).await {
|
||||
Ok(()) => {
|
||||
tracing::info!("[ASYNC_UNREGISTER] Completed for {}", uuid_clone);
|
||||
@@ -1176,6 +1183,7 @@ async fn unregister(
|
||||
let characters_table = schema::table_name("characters");
|
||||
let chunks_rule1_table = schema::table_name("chunks_rule1");
|
||||
let processor_alerts_table = schema::table_name("processor_alerts");
|
||||
let trace_profiles_table = schema::table_name("trace_profiles");
|
||||
|
||||
let mut tx = state.db.pool().begin().await.map_err(|e| {
|
||||
tracing::error!("[unregister] Failed to start transaction: {}", e);
|
||||
@@ -1259,6 +1267,12 @@ async fn unregister(
|
||||
&uuid,
|
||||
"processor versions"
|
||||
);
|
||||
let deleted_trace_profiles = delete_safe!(
|
||||
trace_profiles_table,
|
||||
"file_uuid = $1",
|
||||
&uuid,
|
||||
"trace profiles"
|
||||
);
|
||||
|
||||
sqlx::query(&format!(
|
||||
"DELETE FROM {} WHERE file_uuid = $1",
|
||||
@@ -1278,13 +1292,13 @@ async fn unregister(
|
||||
})?;
|
||||
|
||||
tracing::info!(
|
||||
"[UNREGISTER] Deleted: {} faces, {} processors, {} parent_chunks, {} chunks, {} pre_chunks, {} tkg_nodes, {} cuts, {} strangers, {} chunk_vectors, {} monitor_jobs, {} frames, {} file_identities, {} speaker_detections, {} face_clusters, {} face_recognition_results, {} characters, {} chunks_rule1, {} processor_alerts, {} processor_versions",
|
||||
"[UNREGISTER] Deleted: {} faces, {} processors, {} parent_chunks, {} chunks, {} pre_chunks, {} tkg_nodes, {} cuts, {} strangers, {} chunk_vectors, {} monitor_jobs, {} frames, {} file_identities, {} speaker_detections, {} face_clusters, {} face_recognition_results, {} characters, {} chunks_rule1, {} processor_alerts, {} processor_versions, {} trace_profiles",
|
||||
deleted_faces, deleted_processors, deleted_parent_chunks, deleted_chunks,
|
||||
deleted_pre_chunks, deleted_tkg_nodes, deleted_cuts, deleted_strangers,
|
||||
deleted_chunk_vectors, deleted_monitor_jobs, deleted_frames,
|
||||
deleted_file_identities, deleted_speaker_detections, deleted_face_clusters,
|
||||
deleted_face_recognition, deleted_characters, deleted_chunks_rule1,
|
||||
deleted_processor_alerts, deleted_processor_versions
|
||||
deleted_processor_alerts, deleted_processor_versions, deleted_trace_profiles
|
||||
);
|
||||
|
||||
let deleted_output_files = delete_output_files(&uuid);
|
||||
@@ -1439,6 +1453,7 @@ async fn unregister_internal(state: &AppState, uuid: &str) -> Result<(), StatusC
|
||||
let characters_table = schema::table_name("characters");
|
||||
let chunks_rule1_table = schema::table_name("chunks_rule1");
|
||||
let processor_alerts_table = schema::table_name("processor_alerts");
|
||||
let trace_profiles_table = schema::table_name("trace_profiles");
|
||||
|
||||
let mut tx = state.db.pool().begin().await.map_err(|e| {
|
||||
tracing::error!("[unregister] Failed to start transaction: {}", e);
|
||||
@@ -1518,6 +1533,12 @@ async fn unregister_internal(state: &AppState, uuid: &str) -> Result<(), StatusC
|
||||
uuid,
|
||||
"processor versions"
|
||||
);
|
||||
let _deleted_trace_profiles = delete_safe!(
|
||||
trace_profiles_table,
|
||||
"file_uuid = $1",
|
||||
uuid,
|
||||
"trace profiles"
|
||||
);
|
||||
|
||||
sqlx::query(&format!(
|
||||
"DELETE FROM {} WHERE file_uuid = $1",
|
||||
|
||||
Reference in New Issue
Block a user