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

View File

@@ -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<String>)> =
@@ -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<i32>,
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)