mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-05 17:58:55 +00:00
adjustments
This commit is contained in:
1 parent
204ccad158
commit
f2434d3e74
1 file changed
+16
-8
+16
-8
@@ -1,14 +1,18 @@
|
||||
use chrono::{TimeDelta, Utc};
|
||||
use sqlx::MySqlPool;
|
||||
use enums::by_table::media_files::media_file_class::MediaFileClass;
|
||||
use tokens::tokens::media_files::MediaFileToken;
|
||||
|
||||
/// The serialized value for `MediaFileClass::Video` as stored in the database.
|
||||
const MEDIA_CLASS_VIDEO: &str = MediaFileClass::Video.to_str();
|
||||
const PAGE_SIZE: i64 = 100;
|
||||
const DEFAULT_PAGE_SIZE: i64 = 100;
|
||||
const DEFAULT_MAX_LOOKBACK_HOURS: i32 = 4;
|
||||
|
||||
pub struct ListVideoMediaFilesWithoutThumbnailsArgs<'a> {
|
||||
pub time_delta: TimeDelta,
|
||||
/// Override the maximum number of hours in our lookback window.
|
||||
pub custom_max_lookback_hours: Option<i32>,
|
||||
/// Override how many results to fetch (given a full page of results)
|
||||
pub custom_page_size: Option<i64>,
|
||||
/// Cursor to continue paginating with
|
||||
pub maybe_id_cursor: Option<i64>,
|
||||
pub pool: &'a MySqlPool,
|
||||
}
|
||||
@@ -30,9 +34,13 @@ pub struct VideoMediaFilesWithoutThumbnails {
|
||||
pub async fn list_video_media_files_without_thumbnails_for_job(
|
||||
args: ListVideoMediaFilesWithoutThumbnailsArgs<'_>,
|
||||
) -> Result<VideoMediaFilesWithoutThumbnails, sqlx::Error> {
|
||||
let cutoff = Utc::now() - args.time_delta;
|
||||
let cursor = args.maybe_id_cursor.unwrap_or(i64::MAX);
|
||||
|
||||
let page_size = args.custom_page_size.unwrap_or(DEFAULT_PAGE_SIZE);
|
||||
let max_lookback_hours = args.custom_max_lookback_hours.unwrap_or(DEFAULT_MAX_LOOKBACK_HOURS);
|
||||
|
||||
// NB: `COALESCE ...` helps us force the index for a more performant query plan (otherwise it explodes into a table scan).
|
||||
// NB: `NOW() - INTERVAL ? HOUR` uses the database clock to avoid client/server clock skew.
|
||||
let media_files = sqlx::query_as!(
|
||||
VideoMediaFileWithoutThumbnail,
|
||||
r#"
|
||||
@@ -45,7 +53,7 @@ SELECT
|
||||
maybe_public_bucket_extension
|
||||
FROM media_files
|
||||
WHERE
|
||||
id >= (SELECT COALESCE(MIN(id), 0) FROM media_files WHERE created_at >= ?)
|
||||
id >= (SELECT COALESCE(MIN(id), 0) FROM media_files WHERE created_at >= NOW() - INTERVAL ? HOUR)
|
||||
AND id < ?
|
||||
AND media_class = ?
|
||||
AND maybe_thumbnail_version IS NULL
|
||||
@@ -54,15 +62,15 @@ WHERE
|
||||
ORDER BY id DESC
|
||||
LIMIT ?
|
||||
"#,
|
||||
cutoff,
|
||||
max_lookback_hours,
|
||||
cursor,
|
||||
MEDIA_CLASS_VIDEO,
|
||||
PAGE_SIZE,
|
||||
page_size,
|
||||
)
|
||||
.fetch_all(args.pool)
|
||||
.await?;
|
||||
|
||||
let next_cursor = if media_files.len() as i64 == PAGE_SIZE {
|
||||
let next_cursor = if media_files.len() as i64 == page_size {
|
||||
media_files.last().map(|f| f.id)
|
||||
} else {
|
||||
None
|
||||
|
||||
Reference in new issue
Block a user