goon/alembic/versions
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
..
20260502_0001_initial.py Initial commit 2026-05-20 10:10:22 +02:00
20260502_0002_playback_sources.py Initial commit 2026-05-20 10:10:22 +02:00
20260503_0003_playback_dead.py Initial commit 2026-05-20 10:10:22 +02:00
20260504_0004_animated_thumbnail.py Initial commit 2026-05-20 10:10:22 +02:00
20260504_0005_favorite_performers.py Initial commit 2026-05-20 10:10:22 +02:00
20260504_0006_blacklists.py Initial commit 2026-05-20 10:10:22 +02:00
20260504_0007_play_progress.py Initial commit 2026-05-20 10:10:22 +02:00
20260506_0008_performer_search_meta.py Initial commit 2026-05-20 10:10:22 +02:00
20260506_0009_movies.py Initial commit 2026-05-20 10:10:22 +02:00
20260506_0010_favorite_scenes.py Initial commit 2026-05-20 10:10:22 +02:00
20260507_0011_origin_pornapp_to_tube.py Initial commit 2026-05-20 10:10:22 +02:00
20260508_0012_favorite_studios.py Initial commit 2026-05-20 10:10:22 +02:00
20260509_0013_bug_reports.py Initial commit 2026-05-20 10:10:22 +02:00
20260509_0014_favorite_movies.py Initial commit 2026-05-20 10:10:22 +02:00
20260510_0015_bug_reports_movie_id.py Initial commit 2026-05-20 10:10:22 +02:00
20260512_0016_realdebrid_cache.py Initial commit 2026-05-20 10:10:22 +02:00
20260512_0017_drop_realdebrid_cache.py Initial commit 2026-05-20 10:10:22 +02:00
20260528_0018_movie_play_progress.py feat(movies): watched/continue-watching tracking end-to-end 2026-05-28 23:24:06 +02:00
20260531_0019_taxonomy_scene_counts.py perf(taxonomy): denormalize scene_count for tags/performers/studios 2026-05-31 17:53:48 +02:00
20260602_0020_scene_tags_tag_id_index.py perf(scenes): drop exact count on filtered lists; index scene_tags(tag_id) 2026-06-02 12:00:36 +02:00