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.
This commit is contained in:
Accusys
2026-07-31 14:45:09 +08:00
parent 4a480f46fd
commit d91ce0b4fc
+4 -10
View File
@@ -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<String, Vec<i32>> = 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);
}