Add trending movies/series, refreshed on a schedule
CI / lint (push) Canceled after 0s
CI / typecheck (push) Canceled after 0s
CI / unit-tests (push) Canceled after 0s
CI / integration-tests (push) Canceled after 0s
CI / container-build (push) Canceled after 0s
CI / dependency-audit (push) Canceled after 0s

Mirrors TMDb's own /trending/{movie|tv}/{day|week} ranking rather than
Aurora computing trending itself from popularity deltas -- that would
require re-syncing the entire catalog on a schedule, infeasible at any
real scale, whereas TMDb already computes this well from signals (real
view/search velocity) Aurora has no access to.

New: TrendingEntry model + migration 0003, MetadataProvider.get_trending
(concrete/optional, like aclose(), so existing test fakes don't all need
updating), refresh_trending() which actually ingests each trending item
(only ~20 per window, cheap enough to fully ingest rather than apply the
never-fabricate-a-stub rule recommendations uses), a twice-daily arq cron
job (WorkerSettings.cron_jobs, new to this codebase), a manual admin
trigger for right after a deploy, and GET /movies/trending + GET
/series/trending.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
NixReaper
2026-09-06 05:18:02 -05:00
co-authored by Claude Sonnet 5
parent 6c95e18aad
commit 4403305da6
16 changed files with 513 additions and 2 deletions
+17
View File
@@ -19,6 +19,7 @@ from typing import Any
from app.core.database import session_scope
from app.core.logging import get_logger
from app.providers.tmdb import TMDbProvider
from app.services.artwork.download import download_artwork
from app.services.artwork.storage import get_artwork_storage
from app.services.ingestion.runner import (
@@ -34,6 +35,7 @@ from app.services.ingestion.runner import (
run_season_ingestion,
run_series_ingestion,
)
from app.services.ingestion.trending_ingestion import refresh_trending
logger = get_logger(__name__)
@@ -112,3 +114,18 @@ async def ingest_collection_task(ctx: dict[str, Any], job_id: str, external_id:
async def download_artwork_task(ctx: dict[str, Any], artwork_id: str) -> bool:
async with session_scope() as session:
return await download_artwork(session, get_artwork_storage(), uuid.UUID(artwork_id))
async def refresh_trending_task(ctx: dict[str, Any]) -> None:
"""Runs on a schedule (see WorkerSettings.cron_jobs in
app/workers/worker.py) -- not tracked in ingestion_jobs, same as
download_artwork_task, since there's no single external_id a client
would poll status for."""
provider = TMDbProvider()
try:
for media_type in ("movie", "tv"):
for time_window in ("day", "week"):
await refresh_trending(provider, media_type, time_window)
finally:
await provider.aclose()