fix: resolve trace-profile UPSERT SQL error and face-filter route syntax

- Fixed upsert_trace_profile() SQL: replaced scalar subqueries with LEFT JOIN
  to properly reference trace_profiles table in backfill logic
- Fixed face_filter routes: changed {file_uuid} to :file_uuid syntax for
  axum 0.7.9 compatibility
- Both fixes resolve HTTP 500 errors in rename and 404 errors in face filter
This commit is contained in:
Accusys
2026-08-09 23:41:11 +08:00
parent a3eba898e2
commit d6f45683a0
2 changed files with 20 additions and 22 deletions
+6 -6
View File
@@ -536,10 +536,10 @@ pub async fn get_filter_rules(
/// Create router for face filter API
pub fn face_filter_routes() -> Router<AppState> {
Router::new()
.route("/api/v1/file/{file_uuid}/face-filter/faces", get(get_faces))
.route("/api/v1/file/{file_uuid}/face-filter/{face_id}/report", get(get_face_filter_report))
.route("/api/v1/file/{file_uuid}/face-filter/apply", post(filter_faces))
.route("/api/v1/file/{file_uuid}/face-filter/stats", get(get_filter_stats))
.route("/api/v1/file/{file_uuid}/face-filter/rules", get(get_filter_rules))
.route("/api/v1/file/{file_uuid}/face-filter/rules", post(save_filter_rules))
.route("/api/v1/file/:file_uuid/face-filter/faces", get(get_faces))
.route("/api/v1/file/:file_uuid/face-filter/:face_id/report", get(get_face_filter_report))
.route("/api/v1/file/:file_uuid/face-filter/apply", post(filter_faces))
.route("/api/v1/file/:file_uuid/face-filter/stats", get(get_filter_stats))
.route("/api/v1/file/:file_uuid/face-filter/rules", get(get_filter_rules))
.route("/api/v1/file/:file_uuid/face-filter/rules", post(save_filter_rules))
}
+14 -16
View File
@@ -33,24 +33,29 @@ pub async fn upsert_trace_profile(
let tp_table = table_name("trace_profiles");
let tkg_table = table_name("tkg_nodes");
let tkg_sub = |col: &str| {
format!(
"(SELECT {col} FROM {tkg_table} tn WHERE tn.file_uuid = $1 \
AND tn.node_type = 'face_track' AND (tn.properties->>'trace_id')::int = $2)"
)
};
let update_props = if properties.is_some() {
", properties = EXCLUDED.properties"
} else {
""
};
// Use LEFT JOIN to get tkg_nodes data for backfilling
let sql = format!(
"INSERT INTO {tp_table} (file_uuid, trace_id, name, start_frame, end_frame, \
frame_count, key_frame, key_face, status, avg_confidence, properties) \
VALUES ($1, $2, $3, {sf}, {ef}, {fc}, {kf}, {kface}, 'pending', {avgc}, \
COALESCE($4::jsonb, {props_sub}, '{{}}'::jsonb)) \
SELECT $1, $2, $3, \
COALESCE((tn.properties->>'start_frame')::bigint, tp.start_frame), \
COALESCE((tn.properties->>'end_frame')::bigint, tp.end_frame), \
COALESCE((tn.properties->>'frame_count')::int, tp.frame_count), \
COALESCE(tn.properties->>'key_frame', tp.key_frame), \
COALESCE(tn.properties->>'key_face', tp.key_face), \
'pending', \
COALESCE((tn.properties->>'avg_confidence')::double precision, tp.avg_confidence), \
COALESCE($4::jsonb, tn.properties, '{{}}'::jsonb) \
FROM (VALUES (1)) AS dummy \
LEFT JOIN {tkg_table} tn ON tn.file_uuid = $1 \
AND tn.node_type = 'face_track' AND (tn.properties->>'trace_id')::int = $2 \
LEFT JOIN {tp_table} tp ON tp.file_uuid = $1 AND tp.trace_id = $2 \
ON CONFLICT (file_uuid, trace_id) \
DO UPDATE SET name = EXCLUDED.name{update_props}, \
start_frame = COALESCE(EXCLUDED.start_frame, trace_profiles.start_frame), \
@@ -60,13 +65,6 @@ pub async fn upsert_trace_profile(
key_face = COALESCE(EXCLUDED.key_face, trace_profiles.key_face), \
avg_confidence = COALESCE(EXCLUDED.avg_confidence, trace_profiles.avg_confidence), \
updated_at = NOW()",
sf = tkg_sub("COALESCE((tn.properties->>'start_frame')::bigint, trace_profiles.start_frame)"),
ef = tkg_sub("COALESCE((tn.properties->>'end_frame')::bigint, trace_profiles.end_frame)"),
fc = tkg_sub("COALESCE((tn.properties->>'frame_count')::int, trace_profiles.frame_count)"),
kf = tkg_sub("COALESCE(tn.properties->>'key_frame', trace_profiles.key_frame)"),
kface = tkg_sub("COALESCE(tn.properties->>'key_face', trace_profiles.key_face)"),
avgc = tkg_sub("COALESCE((tn.properties->>'avg_confidence')::double precision, trace_profiles.avg_confidence)"),
props_sub = tkg_sub("tn.properties"),
);
let mut query = sqlx::query(&sql).bind(file_uuid).bind(trace_id).bind(name);