Sample videos randomly for view_count enrichment, not newest-first

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 <noreply@anthropic.com>
This commit is contained in:
2026-05-26 23:06:32 +02:00
parent 6e455ed8ce
commit be7319e96c

View File

@@ -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},