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); }