- Added Upkeeping → Correct catalogue order.
It now recalculates video sort_order from created_at newest-first, so videos with corrected/original publish dates appear first in the homepage and public catalogue. I also updated catalogue/admin/latest-video ordering to use publish date as a tie-breaker after stored sort order.
This commit is contained in:
+38
-1
@@ -56,6 +56,7 @@ function get_db(): PDO {
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_videos_published ON videos(published);
|
||||
CREATE INDEX IF NOT EXISTS idx_videos_sort ON videos(sort_order, id);
|
||||
CREATE INDEX IF NOT EXISTS idx_videos_created ON videos(created_at, id);
|
||||
CREATE INDEX IF NOT EXISTS idx_videos_title ON videos(title);
|
||||
CREATE INDEX IF NOT EXISTS idx_sources_video ON video_sources(video_id);
|
||||
");
|
||||
@@ -768,6 +769,42 @@ function media_correct_external_view_counts(int $limit = 25): array {
|
||||
return media_restore_external_view_counts($limit);
|
||||
}
|
||||
|
||||
function media_catalogue_order_candidate_count(): int {
|
||||
return (int)get_db()->query("SELECT COUNT(*) FROM videos")->fetchColumn();
|
||||
}
|
||||
|
||||
function media_correct_catalogue_sort_order(): array {
|
||||
$db = get_db();
|
||||
$videos = $db->query("
|
||||
SELECT id, sort_order
|
||||
FROM videos
|
||||
ORDER BY datetime(created_at) DESC, created_at DESC, id DESC
|
||||
")->fetchAll();
|
||||
|
||||
$result = [
|
||||
'checked' => count($videos),
|
||||
'updated' => 0,
|
||||
];
|
||||
if (!$videos) return $result;
|
||||
|
||||
$stmt = $db->prepare("UPDATE videos SET sort_order=?, updated_at=datetime('now') WHERE id=?");
|
||||
$db->beginTransaction();
|
||||
try {
|
||||
foreach ($videos as $index => $video) {
|
||||
$sort_order = $index * 10;
|
||||
if ((int)$video['sort_order'] === $sort_order) continue;
|
||||
$stmt->execute([$sort_order, (int)$video['id']]);
|
||||
$result['updated']++;
|
||||
}
|
||||
$db->commit();
|
||||
} catch (Throwable $e) {
|
||||
$db->rollBack();
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function media_youtube_source_url_for_video(int $video_id): string {
|
||||
$stmt = get_db()->prepare("
|
||||
SELECT source_url
|
||||
@@ -1436,7 +1473,7 @@ function get_videos_paginated(int $page, int $per_page, bool $published_only = t
|
||||
LEFT JOIN video_sources vs ON vs.video_id = v.id
|
||||
$where
|
||||
GROUP BY v.id
|
||||
ORDER BY v.sort_order ASC, v.id DESC
|
||||
ORDER BY v.sort_order ASC, datetime(v.created_at) DESC, v.created_at DESC, v.id DESC
|
||||
LIMIT :limit OFFSET :offset
|
||||
");
|
||||
foreach ($bind as $key => $value) $rows->bindValue($key, $value);
|
||||
|
||||
Reference in New Issue
Block a user