diff --git a/app/api/scenes.py b/app/api/scenes.py index 8d30810..3a6f809 100644 --- a/app/api/scenes.py +++ b/app/api/scenes.py @@ -328,8 +328,13 @@ def list_scenes( if _is_pure_default: total = _default_scene_count(session) else: + # PERF (2026-06-02): `base` to `select(Scene)` (wszystkie kolumny). Count nad + # `SELECT scenes.* ... LIMIT 1001` z bound-params psycopg dobierał zły plan i + # zajmował ~4s (has_playback) / ~6s (tags) — mimo że to samo z `SELECT id` / + # literałami robi ~30ms. Liczymy nad samym PK: identyczna semantyka, ~100× szybciej. + count_base = base.with_only_columns(Scene.id) cnt = session.execute( - select(func.count()).select_from(base.limit(_COUNT_CAP + 1).subquery()) + select(func.count()).select_from(count_base.limit(_COUNT_CAP + 1).subquery()) ).scalar_one() if cnt > _COUNT_CAP: total, total_capped = _COUNT_CAP, True