fix: trace_agent_api.rs — replace all dev.* hardcodes with schema::table_name()

This commit is contained in:
Accusys
2026-05-14 02:56:43 +08:00
parent edadb022e1
commit e8f44d7357
+35 -36
View File
@@ -78,7 +78,8 @@ async fn list_traces_sorted(
}; };
let fps: f64 = 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) .bind(&file_uuid)
.fetch_optional(state.db.pool()) .fetch_optional(state.db.pool())
.await .await
@@ -86,33 +87,29 @@ async fn list_traces_sorted(
.unwrap_or(24.0); .unwrap_or(24.0);
let query = format!( let query = format!(
r#"SELECT tt.trace_id, tt.face_count, tt.first_frame, tt.last_frame, "SELECT tt.*, fd.id AS sample_face_id, {} AS video_fps FROM (
ROUND(tt.first_frame::numeric / {}, 1)::float8 AS first_sec, SELECT trace_id,
ROUND(tt.last_frame::numeric / {}, 1)::float8 AS last_sec, COUNT(*) AS face_count,
ROUND((tt.last_frame - tt.first_frame)::numeric / {}, 1)::float8 AS duration_sec, MIN(frame_number) AS first_frame,
ROUND(tt.avg_confidence::numeric, 4)::float8 AS avg_confidence, MAX(frame_number) AS last_frame,
fd.id::text AS sample_face_id AVG(confidence) AS avg_confidence
FROM ( FROM {}
SELECT trace_id, WHERE file_uuid = $1 AND trace_id IS NOT NULL
COUNT(*) AS face_count, AND confidence >= $5 AND confidence <= $6
MIN(frame_number) AS first_frame, GROUP BY trace_id
MAX(frame_number) AS last_frame, HAVING COUNT(*) >= $2
AVG(confidence) AS avg_confidence ORDER BY {}
FROM dev.face_detections LIMIT $3 OFFSET $4
WHERE file_uuid = $1 AND trace_id IS NOT NULL ) tt
AND confidence >= $5 AND confidence <= $6 LEFT JOIN LATERAL (
GROUP BY trace_id SELECT id FROM {}
HAVING COUNT(*) >= $2 WHERE trace_id = tt.trace_id AND file_uuid = $1
ORDER BY {} ORDER BY confidence DESC LIMIT 1
LIMIT $3 OFFSET $4 ) fd ON true",
) tt crate::core::db::schema::table_name("videos"),
LEFT JOIN LATERAL ( crate::core::db::schema::table_name("face_detections"),
SELECT id FROM dev.face_detections order_clause,
WHERE trace_id = tt.trace_id AND file_uuid = $1 crate::core::db::schema::table_name("face_detections"),
ORDER BY confidence DESC LIMIT 1
) fd ON true
"#,
fps, fps, fps, order_clause
); );
let rows: Vec<(i32, i64, i32, i32, f64, f64, f64, f64, Option<String>)> = let rows: Vec<(i32, i64, i32, i32, f64, f64, f64, f64, Option<String>)> =
@@ -143,7 +140,8 @@ async fn list_traces_sorted(
.collect(); .collect();
let (total_traces, total_faces): (i64, i64) = sqlx::query_as( 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) .bind(&file_uuid)
.fetch_one(state.db.pool()) .fetch_one(state.db.pool())
@@ -218,7 +216,8 @@ async fn list_trace_faces(
let interpolate = q.interpolate.unwrap_or(false); let interpolate = q.interpolate.unwrap_or(false);
let fps: f64 = 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) .bind(&file_uuid)
.fetch_optional(state.db.pool()) .fetch_optional(state.db.pool())
.await .await
@@ -226,7 +225,8 @@ async fn list_trace_faces(
.unwrap_or(24.0); .unwrap_or(24.0);
let total_detected: i64 = sqlx::query_scalar( 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(&file_uuid)
.bind(trace_id) .bind(trace_id)
@@ -243,11 +243,10 @@ async fn list_trace_faces(
Option<i32>, Option<i32>,
f32, f32,
)> = sqlx::query_as( )> = sqlx::query_as(
"SELECT id, frame_number, x, y, width, height, confidence &format!("SELECT id, frame_number, x, y, width, height, confidence \
FROM dev.face_detections FROM {} WHERE file_uuid = $1 AND trace_id = $2 \
WHERE file_uuid = $1 AND trace_id = $2 ORDER BY frame_number ASC LIMIT $3 OFFSET $4",
ORDER BY frame_number ASC crate::core::db::schema::table_name("face_detections"))
LIMIT $3 OFFSET $4",
) )
.bind(&file_uuid) .bind(&file_uuid)
.bind(trace_id) .bind(trace_id)