perf(plex): the facets ask the episode rollup once per call, not once per show group
A watch-state scope (watched / in progress / unwatched) joined the per-user episode rollup into each show facet query: five passes over the user's episodes per call, half of a filtered facets request. The shows in scope are now resolved once and every group filters on their ids; the grid-parity test holds the counts. Localdev: 99 -> 61 ms.
This commit is contained in:
@@ -214,3 +214,28 @@ def test_hidden_movie_absent_from_grid_and_facets(db, as_user):
|
||||
facets = client.get("/api/plex/facets?scope=movie&show=all")
|
||||
crs = {c["value"]: c["count"] for c in facets.json()["content_ratings"]}
|
||||
assert crs.get("R") == 1, crs
|
||||
|
||||
|
||||
def test_a_watch_state_scope_rolls_the_episodes_up_once(db, as_user):
|
||||
"""The per-user episode rollup behind a show's watch state is a pass over every episode; each show
|
||||
facet group asked it again (E31 S4e: half of a filtered facets call). It is asked once now."""
|
||||
from sqlalchemy import event
|
||||
|
||||
from app.db import engine
|
||||
|
||||
seed = _seed(db)
|
||||
client = as_user(seed["user"])
|
||||
rollups: list[str] = []
|
||||
|
||||
def count(conn, cursor, statement, *_):
|
||||
if "GROUP BY plex_items.show_id" in statement:
|
||||
rollups.append(statement)
|
||||
|
||||
event.listen(engine, "before_cursor_execute", count)
|
||||
try:
|
||||
for show in ("watched", "in_progress", "unwatched"):
|
||||
rollups.clear()
|
||||
assert client.get(f"/api/plex/facets?scope=both&show={show}").status_code == 200
|
||||
assert len(rollups) == 1, show
|
||||
finally:
|
||||
event.remove(engine, "before_cursor_execute", count)
|
||||
|
||||
Reference in New Issue
Block a user