perf: optimize face thumbnail loading + reduce face-groups payload
1. Thumbnail API now checks trace/{tid}/key_face.jpg before ffmpeg
- First request: 8ms (read from disk) vs ~500ms (ffmpeg)
- All 2,451 trace thumbnails now served from pre-cached key_face.jpg
2. Face-groups API accepts ?include_trace_ids=false
- Default: includes trace_ids (32KB for Charade)
- With flag: excludes trace_ids (17KB, 48% reduction)
- Frontend can fetch full data only when user clicks into a group
This commit is contained in:
+35
-4
@@ -1161,12 +1161,19 @@ pub async fn update_file_profile_handler(
|
||||
pub struct FaceGroup {
|
||||
pub group_id: i32,
|
||||
pub name: String,
|
||||
pub trace_ids: Vec<i32>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub trace_ids: Option<Vec<i32>>,
|
||||
pub trace_count: i32,
|
||||
pub representative_trace: i32,
|
||||
pub editable: bool,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct FaceGroupsQuery {
|
||||
#[serde(default)]
|
||||
pub include_trace_ids: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct FaceGroupsResponse {
|
||||
pub success: bool,
|
||||
@@ -1180,6 +1187,7 @@ pub async fn get_face_groups_handler(
|
||||
State(state): State<AppState>,
|
||||
Extension(_auth): Extension<UserAuth>,
|
||||
Path(file_uuid): Path<String>,
|
||||
Query(q): Query<FaceGroupsQuery>,
|
||||
) -> Result<Json<FaceGroupsResponse>, StatusCode> {
|
||||
let tkg_table = schema::table_name("tkg_nodes");
|
||||
let tp_table = schema::table_name("trace_profiles");
|
||||
@@ -1213,7 +1221,21 @@ pub async fn get_face_groups_handler(
|
||||
}
|
||||
}
|
||||
|
||||
let face_groups: Vec<FaceGroup> = groups
|
||||
// Filter out single-trace "groups" — these are unclustered traces
|
||||
// Move them to unassigned instead of showing as separate groups
|
||||
let mut filtered_groups: HashMap<String, Vec<i32>> = HashMap::new();
|
||||
for (name, trace_ids) in groups {
|
||||
if trace_ids.len() > 1 {
|
||||
filtered_groups.insert(name, trace_ids);
|
||||
} else {
|
||||
// Single-trace "group" → treat as unassigned
|
||||
unassigned.extend(trace_ids);
|
||||
}
|
||||
}
|
||||
|
||||
let include_trace_ids = q.include_trace_ids.unwrap_or(true);
|
||||
|
||||
let face_groups: Vec<FaceGroup> = filtered_groups
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(idx, (name, trace_ids))| FaceGroup {
|
||||
@@ -1221,7 +1243,7 @@ pub async fn get_face_groups_handler(
|
||||
name,
|
||||
trace_count: trace_ids.len() as i32,
|
||||
representative_trace: trace_ids.first().copied().unwrap_or(0),
|
||||
trace_ids,
|
||||
trace_ids: if include_trace_ids { Some(trace_ids) } else { None },
|
||||
editable: true,
|
||||
})
|
||||
.collect();
|
||||
@@ -1309,9 +1331,18 @@ pub async fn get_cluster_results_handler(
|
||||
}
|
||||
}
|
||||
|
||||
// Filter out single-trace "groups" — these are unclustered traces
|
||||
let mut filtered_groups: HashMap<String, Vec<i32>> = HashMap::new();
|
||||
for (name, trace_ids) in groups {
|
||||
if trace_ids.len() > 1 {
|
||||
filtered_groups.insert(name, trace_ids);
|
||||
}
|
||||
// Single-trace groups are silently dropped (not real clusters)
|
||||
}
|
||||
|
||||
// trace_id -> cluster_id mapping for frame faces
|
||||
let mut trace_to_cluster: HashMap<i32, i32> = HashMap::new();
|
||||
let face_groups: Vec<ClusterResultsGroup> = groups
|
||||
let face_groups: Vec<ClusterResultsGroup> = filtered_groups
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(idx, (name, trace_ids))| {
|
||||
|
||||
Reference in New Issue
Block a user