time and blink modified

This commit is contained in:
2026-05-29 18:51:34 +05:30
parent e64a186e94
commit ea7730bef9
4 changed files with 185 additions and 10 deletions

View File

@@ -3141,6 +3141,11 @@ pub struct VideoEntry {
pub completed: bool,
pub completed_at: Option<String>,
pub completed_by: Option<String>,
// Number of live assets in this video with modified=1, and the most
// recent modified_at across them. Lets the UI render an "edited"
// badge + relative time without an extra round-trip per video.
pub modified_count: i64,
pub last_modified_at: Option<String>,
}
/// Sort key for stable numbering: parse the first `YYYY_MMDD_HHMMSS` pattern
@@ -3216,16 +3221,38 @@ pub async fn list_videos(
status.insert(n, (c, at, by));
}
// Aggregate modification stats per video in a single query so the cost
// is O(rows) regardless of how many videos exist.
let mod_rows: Vec<(String, i64, Option<String>)> = sqlx::query_as(
"SELECT video_name,
SUM(CASE WHEN modified = 1 THEN 1 ELSE 0 END) AS mc,
MAX(CASE WHEN modified = 1 THEN modified_at END) AS last_at
FROM assets WHERE deleted = 0
GROUP BY video_name",
)
.fetch_all(&state.pool)
.await
.map_err(|e| e.to_string())?;
let mut mod_map: std::collections::HashMap<String, (i64, Option<String>)> =
std::collections::HashMap::new();
for (n, c, at) in mod_rows {
mod_map.insert(n, (c, at));
}
let mut out: Vec<VideoEntry> = Vec::with_capacity(all.len());
for (idx, n) in all.into_iter().enumerate() {
let (completed, completed_at, completed_by) =
status.remove(&n).unwrap_or((0, None, None));
let (modified_count, last_modified_at) =
mod_map.remove(&n).unwrap_or((0, None));
out.push(VideoEntry {
video_number: (idx + 1) as i64,
video_name: n,
completed: completed != 0,
completed_at,
completed_by,
modified_count,
last_modified_at,
});
}
Ok(out)