goon/app/models
jtrzupek 2163fee245 perf(taxonomy): denormalize scene_count for tags/performers/studios
Counts for /tags, /performers, /studios and /favorites were computed live
per-request by aggregating scene_tags / scene_performers with an EXISTS to
playback_sources. As the catalog grew to ~1.7M scenes (6.3M scene_tags) this
ran ~4.3s for /tags?order=popular (x2 incl. the total count) and ~950ms for
the default /scenes count, making those screens load in several seconds.

- migration 0019: add scene_count (+ DESC index) to tags/performers/studios
- background job _job_refresh_taxonomy_counts (every 3h) recomputes the counts
  in one UPDATE..FROM each (IS DISTINCT FROM to skip unchanged rows)
- /tags, /performers, /studios scenes path now read the column + ORDER BY the
  indexed scene_count; for_movies paths keep live aggregation (small tables)
- favorites read denormalized scene_count instead of a grouped EXISTS aggregate
- /scenes default count: 10-min in-process TTL cache (header is approximate)

Measured: /tags?order=popular&per_page=500 ~8s -> 66ms incl. serialization.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-05-31 17:53:48 +02:00
..
__init__.py feat(movies): watched/continue-watching tracking end-to-end 2026-05-28 23:24:06 +02:00
base.py Initial commit 2026-05-20 10:10:22 +02:00
blacklist.py Initial commit 2026-05-20 10:10:22 +02:00
bug_report.py Initial commit 2026-05-20 10:10:22 +02:00
external_record.py Initial commit 2026-05-20 10:10:22 +02:00
favorite_movie.py Initial commit 2026-05-20 10:10:22 +02:00
favorite_performer.py Initial commit 2026-05-20 10:10:22 +02:00
favorite_scene.py Initial commit 2026-05-20 10:10:22 +02:00
favorite_studio.py Initial commit 2026-05-20 10:10:22 +02:00
ingest_run.py Initial commit 2026-05-20 10:10:22 +02:00
merge_candidate.py Initial commit 2026-05-20 10:10:22 +02:00
movie.py Initial commit 2026-05-20 10:10:22 +02:00
movie_playback_source.py Initial commit 2026-05-20 10:10:22 +02:00
performer.py perf(taxonomy): denormalize scene_count for tags/performers/studios 2026-05-31 17:53:48 +02:00
play_progress.py feat(movies): watched/continue-watching tracking end-to-end 2026-05-28 23:24:06 +02:00
playback_source.py Initial commit 2026-05-20 10:10:22 +02:00
scene.py Initial commit 2026-05-20 10:10:22 +02:00
source.py Initial commit 2026-05-20 10:10:22 +02:00
studio.py perf(taxonomy): denormalize scene_count for tags/performers/studios 2026-05-31 17:53:48 +02:00
tag.py perf(taxonomy): denormalize scene_count for tags/performers/studios 2026-05-31 17:53:48 +02:00