fix: scan job_id via LEFT JOIN LATERAL monitor_jobs instead of stale videos.job_id column

This commit is contained in:
Accusys
2026-05-19 02:49:53 +08:00
parent 538eea6406
commit 1c42004abf

View File

@@ -2761,9 +2761,16 @@ async fn scan_files(
// 1. Get registered files from DB (Map key: absolute file_path)
let table = schema::table_name("videos");
let mj_table = schema::table_name("monitor_jobs");
let registered_db: Vec<(String, String, String, String, Option<String>, Option<i32>)> = sqlx::query_as(&format!(
"SELECT file_path, file_name, file_uuid, status, registration_time::text, job_id FROM {} ORDER BY id",
table
"SELECT v.file_path, v.file_name, v.file_uuid, v.status, v.registration_time::text, \
latest_job.id as job_id \
FROM {} v \
LEFT JOIN LATERAL ( \
SELECT id FROM {} WHERE uuid = v.file_uuid ORDER BY id DESC LIMIT 1 \
) latest_job ON true \
ORDER BY v.id",
table, mj_table
))
.fetch_all(state.db.pool())
.await