Popular: write Phase 1 immediately, enrich view_count in background

Previously the task waited for all 30 parallel metadata fetches before
writing anything to the DB (~30s). Now Phase 1 (flat-playlist IDs +
basic info) commits to channel_popular_videos immediately (~5s), so the
tab populates fast. Phase 2 (view_count + dates) runs in a daemon thread
while the user is already browsing.

Also: catch table-not-found errors in the sort=popular query so a cold
server returns [] instead of 500. Frontend refetch wait 35s→8s to match
the faster Phase 1 commit time.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-26 22:47:42 +02:00
parent be88d70935
commit 77cba81ef4
2 changed files with 69 additions and 48 deletions

View File

@@ -117,7 +117,7 @@ export default function ChannelPage() {
const popularMut = useMutation({
mutationFn: () => fetchPopularVideos(id),
onSuccess: () => scheduleRefetch(35000),
onSuccess: () => scheduleRefetch(8000),
});
const deepSearchMut = useMutation({