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
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:
co-authored by
Claude Sonnet 5
parent
6c95e18aad
commit
4403305da6
@@ -0,0 +1,40 @@
|
||||
"""Data access for TrendingEntry."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import uuid
|
||||
|
||||
from sqlalchemy import delete, select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.models.trending import TrendingEntry
|
||||
|
||||
|
||||
async def get_trending_entity_ids(
|
||||
session: AsyncSession, *, entity_type: str, time_window: str
|
||||
) -> list[uuid.UUID]:
|
||||
stmt = (
|
||||
select(TrendingEntry.entity_id)
|
||||
.where(TrendingEntry.entity_type == entity_type, TrendingEntry.time_window == time_window)
|
||||
.order_by(TrendingEntry.rank.asc())
|
||||
)
|
||||
result = await session.execute(stmt)
|
||||
return list(result.scalars().all())
|
||||
|
||||
|
||||
async def replace_trending(
|
||||
session: AsyncSession, *, entity_type: str, time_window: str, entity_ids: list[uuid.UUID]
|
||||
) -> None:
|
||||
"""Replace a window's trending snapshot wholesale, same delete-then-
|
||||
recreate approach as ReleaseDate/WatchProviderOffering -- there is no
|
||||
history to preserve, only the current ranking."""
|
||||
|
||||
await session.execute(
|
||||
delete(TrendingEntry).where(
|
||||
TrendingEntry.entity_type == entity_type, TrendingEntry.time_window == time_window
|
||||
)
|
||||
)
|
||||
for rank, entity_id in enumerate(entity_ids):
|
||||
session.add(
|
||||
TrendingEntry(entity_type=entity_type, entity_id=entity_id, time_window=time_window, rank=rank)
|
||||
)
|
||||
Reference in New Issue
Block a user