fix: scan job_id via LEFT JOIN LATERAL monitor_jobs instead of stale videos.job_id column
This commit is contained in:
@@ -2761,9 +2761,16 @@ async fn scan_files(
|
|||||||
|
|
||||||
// 1. Get registered files from DB (Map key: absolute file_path)
|
// 1. Get registered files from DB (Map key: absolute file_path)
|
||||||
let table = schema::table_name("videos");
|
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!(
|
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",
|
"SELECT v.file_path, v.file_name, v.file_uuid, v.status, v.registration_time::text, \
|
||||||
table
|
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())
|
.fetch_all(state.db.pool())
|
||||||
.await
|
.await
|
||||||
|
|||||||
Reference in New Issue
Block a user