goon/app/api
jtrzupek 983bf62416 perf(scenes): drop exact count on filtered lists; index scene_tags(tag_id)
The filtered scene-list endpoints (default feed sends min_duration_sec=60, plus
has_playback / tag / q filters) took ~4.5s — and an idle server. Profiling showed
the entire cost was the bounded COUNT subquery over the EXISTS filters: Postgres
would not reliably early-terminate at the cap under psycopg bound params, scanning
the whole matching set (~858k for has_playback). Counting over the PK and using a
literal LIMIT helped some cases but the plan stayed unstable.

Fix: stop computing an exact count for filtered lists entirely. The mobile client
paginates by has_more (per_page+1 fetch), never by total — total is only the "N+"
UI counter. Derive total as a lower bound from the page + has_more after the fetch.
This removes the count query from every filtered request.

Result (end-to-end, authenticated): default feed 4.5s -> ~0.1s, has_playback
4.4s -> ~0.1s, q/studio/normal-tag filters all <0.3s. Also added index
scene_tags(tag_id, scene_id) (PK led with scene_id, so tag->scenes did a seq scan).

Remaining: a single enormous tag (e.g. "anal", ~163k scenes) ordered by recency
still gathers-all-then-sorts in the fetch (~5s); normal tags are <0.5s. Tracked
in #22 for a denormalized recency-ordered approach.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-02 12:00:36 +02:00
..
__init__.py Initial commit 2026-05-20 10:10:22 +02:00
admin.py Initial commit 2026-05-20 10:10:22 +02:00
admin_html.py Initial commit 2026-05-20 10:10:22 +02:00
blacklist.py Initial commit 2026-05-20 10:10:22 +02:00
bug_reports.py Initial commit 2026-05-20 10:10:22 +02:00
expo_updates.py session work: bug-report fixes + WIP cleanup 2026-05-25 22:02:52 +02:00
favorites.py perf(taxonomy): denormalize scene_count for tags/performers/studios 2026-05-31 17:53:48 +02:00
movies.py feat(movies): watched/continue-watching tracking end-to-end 2026-05-28 23:24:06 +02:00
playback.py session work: bug-report fixes + WIP cleanup 2026-05-25 22:02:52 +02:00
scene_favorites.py Initial commit 2026-05-20 10:10:22 +02:00
scenes.py perf(scenes): drop exact count on filtered lists; index scene_tags(tag_id) 2026-06-02 12:00:36 +02:00
schemas.py perf(scenes): bounded count + has_more for filtered scene lists 2026-05-31 19:24:26 +02:00
seo.py feat(seo): public HTML SEO router + templates; add CLAUDE.md; ignore .nimbalyst 2026-05-31 16:29:59 +02:00
sources.py session work: bug-report fixes + WIP cleanup 2026-05-25 22:02:52 +02:00
stream_proxy.py session work: bug-report fixes + WIP cleanup 2026-05-25 22:02:52 +02:00
taxonomies.py perf(taxonomy): denormalize scene_count for tags/performers/studios 2026-05-31 17:53:48 +02:00
watch.py feat(movies): watched/continue-watching tracking end-to-end 2026-05-28 23:24:06 +02:00