From d91ce0b4fc0f37bb10c8075d955dea6683bbd9ad Mon Sep 17 00:00:00 2001 From: Accusys Date: Fri, 31 Jul 2026 14:45:09 +0800 Subject: [PATCH] fix: cluster-results trace_id mapping (same bug as face-groups) get_cluster_results_handler derived each group's trace_ids from COALESCE(tp.properties, tn.properties)->>'trace_id'. Since trace_profiles.properties is {} this was NULL -> fell back to 0 for every row, so ALL groups reported trace_ids:[0] and collapsed to the same representative trace. Studio's People view renders groups from cluster-results, so every group showed the same face (trace 0) and "Delete all" / "Merge" operated on phantom data: batchDeleteGroups deleted trace 0 repeatedly and never touched the real traces, which is why delete-all appeared to work but left 16 groups behind and merge kept failing. Now reads the real tp.trace_id (fallback tn.properties->>'trace_id'), matching the face-groups fix in 4a480f46. Verified on 9cbeb112: 17 distinct traces now map correctly across 15 groups, no duplicate 0. --- src/api/profile.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/api/profile.rs b/src/api/profile.rs index 20b5962c..2b83f712 100644 --- a/src/api/profile.rs +++ b/src/api/profile.rs @@ -1284,14 +1284,14 @@ pub async fn get_cluster_results_handler( let tp_table = schema::table_name("trace_profiles"); // 1. Build face groups (same grouping logic as face-groups handler) - let rows: Vec<(String, serde_json::Value)> = sqlx::query_as(&format!( + let rows: Vec<(String, i32)> = sqlx::query_as(&format!( "SELECT COALESCE(tp.name, tn.label) as name, \ - COALESCE(tp.properties, tn.properties) as properties \ + COALESCE(tp.trace_id, (tn.properties->>'trace_id')::int) as trace_id \ FROM {} tn \ LEFT JOIN {} tp ON tp.file_uuid = tn.file_uuid \ AND tp.trace_id = (tn.properties->>'trace_id')::int \ WHERE tn.file_uuid = $1 AND tn.node_type = 'face_track' \ - ORDER BY (COALESCE(tp.properties, tn.properties)->>'trace_id')::int", + ORDER BY trace_id", tkg_table, tp_table )) .bind(&file_uuid) @@ -1303,13 +1303,7 @@ pub async fn get_cluster_results_handler( })?; let mut groups: HashMap> = HashMap::new(); - for (name, properties) in rows { - let trace_id = properties - .get("trace_id") - .and_then(|v| v.as_i64()) - .map(|v| v as i32) - .unwrap_or(0); - + for (name, trace_id) in rows { if !(name.starts_with("Face Trace ") || name.starts_with("Trace ")) { groups.entry(name).or_default().push(trace_id); }