From e8f44d735790a2e0be78c8e49df47a3b4c4e4920 Mon Sep 17 00:00:00 2001 From: Accusys Date: Thu, 14 May 2026 02:56:43 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20trace=5Fagent=5Fapi.rs=20=E2=80=94=20rep?= =?UTF-8?q?lace=20all=20dev.*=20hardcodes=20with=20schema::table=5Fname()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/trace_agent_api.rs | 71 +++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/src/api/trace_agent_api.rs b/src/api/trace_agent_api.rs index f2f9bcc..74e580c 100644 --- a/src/api/trace_agent_api.rs +++ b/src/api/trace_agent_api.rs @@ -78,7 +78,8 @@ async fn list_traces_sorted( }; let fps: f64 = - sqlx::query_scalar("SELECT COALESCE(fps, 24.0) FROM dev.videos WHERE file_uuid = $1") + sqlx::query_scalar(&format!("SELECT COALESCE(fps, 24.0) FROM {} WHERE file_uuid = $1", + crate::core::db::schema::table_name("videos"))) .bind(&file_uuid) .fetch_optional(state.db.pool()) .await @@ -86,33 +87,29 @@ async fn list_traces_sorted( .unwrap_or(24.0); let query = format!( - r#"SELECT tt.trace_id, tt.face_count, tt.first_frame, tt.last_frame, - ROUND(tt.first_frame::numeric / {}, 1)::float8 AS first_sec, - ROUND(tt.last_frame::numeric / {}, 1)::float8 AS last_sec, - ROUND((tt.last_frame - tt.first_frame)::numeric / {}, 1)::float8 AS duration_sec, - ROUND(tt.avg_confidence::numeric, 4)::float8 AS avg_confidence, - fd.id::text AS sample_face_id - FROM ( - SELECT trace_id, - COUNT(*) AS face_count, - MIN(frame_number) AS first_frame, - MAX(frame_number) AS last_frame, - AVG(confidence) AS avg_confidence - FROM dev.face_detections - WHERE file_uuid = $1 AND trace_id IS NOT NULL - AND confidence >= $5 AND confidence <= $6 - GROUP BY trace_id - HAVING COUNT(*) >= $2 - ORDER BY {} - LIMIT $3 OFFSET $4 - ) tt - LEFT JOIN LATERAL ( - SELECT id FROM dev.face_detections - WHERE trace_id = tt.trace_id AND file_uuid = $1 - ORDER BY confidence DESC LIMIT 1 - ) fd ON true - "#, - fps, fps, fps, order_clause + "SELECT tt.*, fd.id AS sample_face_id, {} AS video_fps FROM ( + SELECT trace_id, + COUNT(*) AS face_count, + MIN(frame_number) AS first_frame, + MAX(frame_number) AS last_frame, + AVG(confidence) AS avg_confidence + FROM {} + WHERE file_uuid = $1 AND trace_id IS NOT NULL + AND confidence >= $5 AND confidence <= $6 + GROUP BY trace_id + HAVING COUNT(*) >= $2 + ORDER BY {} + LIMIT $3 OFFSET $4 + ) tt + LEFT JOIN LATERAL ( + SELECT id FROM {} + WHERE trace_id = tt.trace_id AND file_uuid = $1 + ORDER BY confidence DESC LIMIT 1 + ) fd ON true", + crate::core::db::schema::table_name("videos"), + crate::core::db::schema::table_name("face_detections"), + order_clause, + crate::core::db::schema::table_name("face_detections"), ); let rows: Vec<(i32, i64, i32, i32, f64, f64, f64, f64, Option)> = @@ -143,7 +140,8 @@ async fn list_traces_sorted( .collect(); let (total_traces, total_faces): (i64, i64) = sqlx::query_as( - "SELECT COUNT(DISTINCT trace_id), COUNT(*) FROM dev.face_detections WHERE file_uuid = $1 AND trace_id IS NOT NULL" + &format!("SELECT COUNT(DISTINCT trace_id), COUNT(*) FROM {} WHERE file_uuid = $1 AND trace_id IS NOT NULL", + crate::core::db::schema::table_name("face_detections")) ) .bind(&file_uuid) .fetch_one(state.db.pool()) @@ -218,7 +216,8 @@ async fn list_trace_faces( let interpolate = q.interpolate.unwrap_or(false); let fps: f64 = - sqlx::query_scalar("SELECT COALESCE(fps, 24.0) FROM dev.videos WHERE file_uuid = $1") + sqlx::query_scalar(&format!("SELECT COALESCE(fps, 24.0) FROM {} WHERE file_uuid = $1", + crate::core::db::schema::table_name("videos"))) .bind(&file_uuid) .fetch_optional(state.db.pool()) .await @@ -226,7 +225,8 @@ async fn list_trace_faces( .unwrap_or(24.0); let total_detected: i64 = sqlx::query_scalar( - "SELECT COUNT(*) FROM dev.face_detections WHERE file_uuid = $1 AND trace_id = $2", + &format!("SELECT COUNT(*) FROM {} WHERE file_uuid = $1 AND trace_id = $2", + crate::core::db::schema::table_name("face_detections")) ) .bind(&file_uuid) .bind(trace_id) @@ -243,11 +243,10 @@ async fn list_trace_faces( Option, f32, )> = sqlx::query_as( - "SELECT id, frame_number, x, y, width, height, confidence - FROM dev.face_detections - WHERE file_uuid = $1 AND trace_id = $2 - ORDER BY frame_number ASC - LIMIT $3 OFFSET $4", + &format!("SELECT id, frame_number, x, y, width, height, confidence \ + FROM {} WHERE file_uuid = $1 AND trace_id = $2 \ + ORDER BY frame_number ASC LIMIT $3 OFFSET $4", + crate::core::db::schema::table_name("face_detections")) ) .bind(&file_uuid) .bind(trace_id)