feat: sync_trace_label unified function + fix is_tkg_done
- Created trace_sync module with sync_trace_label() to sync labels across: 1. tkg_nodes.label (PostgreSQL) 2. trace_profiles.name (PostgreSQL) 3. trace_profile.json label (FS) 4. Qdrant _faces payload.label (NEW - was missing) - Fixed is_tkg_done: allow 0 trace dirs if tkg_nodes exist (prevents permanent stuck in 'Scanning' status) - Updated Face Cluster to use sync_trace_label - Updated merge_trace to use sync_trace_label + cleanup source dir - Created Face_Operations_Complete.md reference document (consolidates all face-related docs into single source of truth)
This commit is contained in:
@@ -2488,6 +2488,64 @@ async fn merge_trace(
|
||||
.execute(state.db.pool())
|
||||
.await;
|
||||
|
||||
// Step 2c: Clean up source trace directory (FS)
|
||||
let output_dir = crate::core::config::OUTPUT_DIR.as_str();
|
||||
let source_trace_dir = std::path::Path::new(output_dir)
|
||||
.join(&file_uuid)
|
||||
.join(format!("trace_{}", trace_id));
|
||||
if source_trace_dir.exists() {
|
||||
let _ = std::fs::remove_dir_all(&source_trace_dir);
|
||||
tracing::info!(
|
||||
"[merge_trace] Removed source trace directory: {:?}",
|
||||
source_trace_dir
|
||||
);
|
||||
}
|
||||
|
||||
// Step 2d: Sync target trace label using sync_trace_label
|
||||
// Get target trace label from existing tkg_nodes
|
||||
let target_ext_id = format!("trace_{}", target_trace_id);
|
||||
let target_label: Option<String> = sqlx::query_scalar(&format!(
|
||||
"SELECT label FROM {} WHERE file_uuid = $1 AND node_type = 'face_track' AND external_id = $2",
|
||||
nodes_table
|
||||
))
|
||||
.bind(&file_uuid)
|
||||
.bind(&target_ext_id)
|
||||
.fetch_optional(state.db.pool())
|
||||
.await
|
||||
.ok()
|
||||
.flatten();
|
||||
|
||||
if let Some(label) = target_label {
|
||||
match crate::core::trace_sync::sync_trace_label(
|
||||
state.db.pool(),
|
||||
&qdrant,
|
||||
&file_uuid,
|
||||
target_trace_id,
|
||||
&label,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(sync_result) => {
|
||||
tracing::info!(
|
||||
"[merge_trace] sync_trace_label for target trace_{}: tkg={}, tp={}, fs={}, qdrant={} ({} points)",
|
||||
target_trace_id,
|
||||
sync_result.tkg_nodes_updated,
|
||||
sync_result.trace_profiles_updated,
|
||||
sync_result.fs_updated,
|
||||
sync_result.qdrant_updated,
|
||||
sync_result.qdrant_points_count
|
||||
);
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::warn!(
|
||||
"[merge_trace] sync_trace_label failed for target trace_{}: {}",
|
||||
target_trace_id,
|
||||
e
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Step 3: Save operation snapshot for undo
|
||||
let op_table = crate::core::db::schema::table_name("trace_operation_history");
|
||||
let _ = sqlx::query(&format!(
|
||||
|
||||
Reference in New Issue
Block a user