From be7319e96ce28df61b96e152c054535e96a1eafd Mon Sep 17 00:00:00 2001 From: Mattias Thall Date: Tue, 26 May 2026 23:06:32 +0200 Subject: [PATCH] Sample videos randomly for view_count enrichment, not newest-first MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously ORDER BY published_at DESC meant only the newest 200 videos ever got view counts. Now ORDER BY RANDOM() spreads the 200 slots across the full channel history — videos without a count are still prioritised, but among those they're drawn randomly. Each run of Fetch Popular covers a different slice, converging toward full coverage over time. Co-Authored-By: Claude Sonnet 4.6 --- backend/routers/channels.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/routers/channels.py b/backend/routers/channels.py index 6e8252f..41b1e53 100644 --- a/backend/routers/channels.py +++ b/backend/routers/channels.py @@ -730,7 +730,7 @@ def _fetch_popular_task(channel_id: int, youtube_channel_id: str): text(""" SELECT youtube_video_id FROM videos WHERE channel_id = :cid - ORDER BY (view_count IS NULL) DESC, published_at DESC NULLS LAST + ORDER BY (view_count IS NULL) DESC, RANDOM() LIMIT 200 """), {"cid": channel_id},