docs: trace_profile UPSERT fixes + Studio face group API gap analysis

- profile.rs: single/group/merge_groups/undo all use upsert_trace_profile
- trace_agent_api.rs: hard delete/merge snapshot + delete trace_profiles
- cluster_agent.rs, job_worker.rs: background name writes use UPSERT
- schema.rs: upsert_trace_profile helper (backfill from tkg_nodes)
- Studio 3 API gaps documented (cluster-results/identity-matches/similar)
This commit is contained in:
Accusys
2026-07-31 11:16:18 +08:00
parent 7272077b65
commit aab727b297
6 changed files with 464 additions and 101 deletions
+58
View File
@@ -1770,6 +1770,18 @@ async fn delete_trace(
.await
.unwrap_or_default();
// 2b. Save trace profile before deleting
let tp_table = crate::core::db::schema::table_name("trace_profiles");
let profile_snapshot: Vec<(i32, Option<String>, serde_json::Value)> = sqlx::query_as(&format!(
"SELECT trace_id, name, properties FROM {} WHERE file_uuid = $1 AND trace_id = $2",
tp_table
))
.bind(&file_uuid)
.bind(trace_id)
.fetch_all(state.db.pool())
.await
.unwrap_or_default();
// 3. Delete from _faces
let _ = qdrant.delete_points_by_filter("_faces", filter.clone()).await;
@@ -1784,6 +1796,16 @@ async fn delete_trace(
.execute(state.db.pool())
.await;
// 4b. Delete trace profile
let _ = sqlx::query(&format!(
"DELETE FROM {} WHERE file_uuid = $1 AND trace_id = $2",
tp_table
))
.bind(&file_uuid)
.bind(trace_id)
.execute(state.db.pool())
.await;
// 5. Save operation snapshot
let op_table = crate::core::db::schema::table_name("trace_operation_history");
let before_snapshot = serde_json::json!({
@@ -1795,6 +1817,13 @@ async fn delete_trace(
"properties": props,
})
}).collect::<Vec<_>>(),
"trace_profiles": profile_snapshot.iter().map(|(tid, name, props)| {
serde_json::json!({
"trace_id": tid,
"name": name,
"properties": props,
})
}).collect::<Vec<_>>(),
});
let _ = sqlx::query(&format!(
"INSERT INTO {} (file_uuid, operation, before_snapshot) VALUES ($1, 'hard_delete', $2)",
@@ -1924,6 +1953,18 @@ async fn merge_trace(
.await
.unwrap_or_default();
// Snapshot source trace profile before merge
let tp_table = crate::core::db::schema::table_name("trace_profiles");
let profile_snapshot: Vec<(i32, Option<String>, serde_json::Value)> = sqlx::query_as(&format!(
"SELECT trace_id, name, properties FROM {} WHERE file_uuid = $1 AND trace_id = $2",
tp_table
))
.bind(&file_uuid)
.bind(trace_id)
.fetch_all(state.db.pool())
.await
.unwrap_or_default();
let before_snapshot = serde_json::json!({
"source_trace_id": trace_id,
"target_trace_id": target_trace_id,
@@ -1935,6 +1976,13 @@ async fn merge_trace(
"properties": props,
})
}).collect::<Vec<_>>(),
"trace_profiles": profile_snapshot.iter().map(|(tid, name, props)| {
serde_json::json!({
"trace_id": tid,
"name": name,
"properties": props,
})
}).collect::<Vec<_>>(),
});
// Step 1: Update all face points from source trace to target trace
@@ -1990,6 +2038,16 @@ async fn merge_trace(
}
};
// Step 2b: Delete source trace profile
let _ = sqlx::query(&format!(
"DELETE FROM {} WHERE file_uuid = $1 AND trace_id = $2",
tp_table
))
.bind(&file_uuid)
.bind(trace_id)
.execute(state.db.pool())
.await;
// Step 3: Save operation snapshot for undo
let op_table = crate::core::db::schema::table_name("trace_operation_history");
let _ = sqlx::query(&format!(