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
@@ -10,7 +10,7 @@ from app.core.ids import aurora_id, parse_aurora_id
|
||||
from app.models.credit import Credit
|
||||
from app.models.enums import ArtworkType, CompanyType, SeriesStatus
|
||||
from app.models.tv import Series
|
||||
from app.repositories import polymorphic, tv_repository
|
||||
from app.repositories import polymorphic, trending_repository, tv_repository
|
||||
from app.schemas.common import CastCreditOut, CompanyBriefOut, CrewCreditOut, GenreOut, KeywordOut
|
||||
from app.schemas.tv import (
|
||||
EpisodeBriefOut,
|
||||
@@ -316,6 +316,30 @@ async def build_series_summaries(
|
||||
return out
|
||||
|
||||
|
||||
_TRENDING_WINDOWS = ("day", "week")
|
||||
|
||||
|
||||
async def list_trending(
|
||||
session: AsyncSession, *, time_window: str, page: int, page_size: int
|
||||
) -> SeriesListOut:
|
||||
if time_window not in _TRENDING_WINDOWS:
|
||||
raise InvalidSeriesFilterError(f"unknown time_window: {time_window!r}")
|
||||
|
||||
all_ids = await trending_repository.get_trending_entity_ids(
|
||||
session, entity_type="series", time_window=time_window
|
||||
)
|
||||
total = len(all_ids)
|
||||
start = (page - 1) * page_size
|
||||
page_ids = all_ids[start : start + page_size]
|
||||
series_rows = await tv_repository.get_series_by_ids(session, page_ids)
|
||||
results = [await _series_summary_from_row(session, s) for s in series_rows]
|
||||
total_pages = (total + page_size - 1) // page_size if total else 0
|
||||
|
||||
return SeriesListOut(
|
||||
page=page, page_size=page_size, total_results=total, total_pages=total_pages, results=results
|
||||
)
|
||||
|
||||
|
||||
async def list_series(
|
||||
session: AsyncSession,
|
||||
*,
|
||||
|
||||
Reference in New Issue
Block a user