Popular tab now shows only flagged popular videos in rank order

Add channel_popular_videos table (channel_id, video_id, rank).
_fetch_popular_task clears and rewrites this table after each fetch.
GET /channels/{id}/videos?sort=popular now JOINs this table and orders
by rank instead of view_count, so the tab shows exactly the videos
YouTube returned in popularity order — nothing more.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-26 22:38:53 +02:00
parent 2f37072187
commit 112f87e764
2 changed files with 66 additions and 24 deletions

View File

@@ -87,6 +87,14 @@ def on_startup():
crawled_at DATETIME DEFAULT CURRENT_TIMESTAMP
)""",
"ALTER TABLE playlists ADD COLUMN video_ids TEXT",
"""CREATE TABLE IF NOT EXISTS channel_popular_videos (
id INTEGER PRIMARY KEY AUTOINCREMENT,
channel_id INTEGER NOT NULL REFERENCES channels(id) ON DELETE CASCADE,
video_id INTEGER NOT NULL REFERENCES videos(id) ON DELETE CASCADE,
rank INTEGER NOT NULL,
fetched_at DATETIME DEFAULT CURRENT_TIMESTAMP,
UNIQUE(channel_id, video_id)
)""",
"""CREATE TABLE IF NOT EXISTS search_history (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,