fix(plex): address S1 code-review findings
- Restore synchronize_session=False on the remove-bulk Core delete (the 2.0 default is 'auto'; keep the pre-conversion contract explicit). - _episode_nav: list(...scalars()) instead of [r[0] for r in ...all()], matching the house style used across the conversion. - Extract app/plex/lookups.by_rating_key() and migrate the get-by-rating_key pattern at 13 sites (imgcache x4, _shared.item_or_404, playback show/season, browse x6). - Coverage: add TestFacetsWithData (the converted wsq aggregation with real data — the highest-risk untested builder), TestPlaylistAndCollectionEndpoints (playlist CRUD + collections list), and an item-state playback test. Full suite 256 passed, 2 skipped; ruff clean.
This commit is contained in:
@@ -9,11 +9,11 @@ The cache directory (``cache.CACHE_DIR``) is shared with the subtitle cache (see
|
||||
"""
|
||||
|
||||
from fastapi import Response
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.models import PlexCollection, PlexItem, PlexSeason, PlexShow
|
||||
from app.plex.cache import CACHE_DIR
|
||||
from app.plex.lookups import by_rating_key
|
||||
|
||||
_EXT_CT = [("jpg", "image/jpeg"), ("png", "image/png"), ("webp", "image/webp")]
|
||||
_CT_EXT = {ct: ext for ext, ct in _EXT_CT}
|
||||
@@ -25,24 +25,16 @@ SIZES = {"thumb": (400, 600), "art": (1280, 720)}
|
||||
def key_for(db: Session, rating_key: str, variant: str) -> str | None:
|
||||
"""The stored Plex image path for a known rating_key (item/show/season). Only mirrored keys
|
||||
are proxyable — this is not an open image proxy."""
|
||||
it = db.execute(
|
||||
select(PlexItem).where(PlexItem.rating_key == rating_key)
|
||||
).scalars().first()
|
||||
it = by_rating_key(db, PlexItem, rating_key)
|
||||
if it is not None:
|
||||
return it.art_key if variant == "art" else it.thumb_key
|
||||
sh = db.execute(
|
||||
select(PlexShow).where(PlexShow.rating_key == rating_key)
|
||||
).scalars().first()
|
||||
sh = by_rating_key(db, PlexShow, rating_key)
|
||||
if sh is not None:
|
||||
return sh.art_key if variant == "art" else sh.thumb_key
|
||||
se = db.execute(
|
||||
select(PlexSeason).where(PlexSeason.rating_key == rating_key)
|
||||
).scalars().first()
|
||||
se = by_rating_key(db, PlexSeason, rating_key)
|
||||
if se is not None:
|
||||
return se.thumb_key
|
||||
col = db.execute(
|
||||
select(PlexCollection).where(PlexCollection.rating_key == rating_key)
|
||||
).scalars().first()
|
||||
col = by_rating_key(db, PlexCollection, rating_key)
|
||||
if col is not None:
|
||||
return col.thumb_key
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user