diff --git a/app/api/scenes.py b/app/api/scenes.py index e8c684c..7426c4a 100644 --- a/app/api/scenes.py +++ b/app/api/scenes.py @@ -764,7 +764,21 @@ def list_scenes( ).all() id_by_slug = {slug: tid for slug, tid, _ in tag_rows} if sort == "release_date" and tag_rows: - tag_sort_id = min(tag_rows, key=lambda r: r[2] or 0)[1] + smallest = min(tag_rows, key=lambda r: r[2] or 0) + tag_sort_id = smallest[1] + # Ekran serwisu z tagiem: idziemy po mniejszej stronie. Gdy serwis ma mniej scen + # niz najmniejszy tag, przejscie po indeksie tagu przez caly katalog szukalo + # rzadkich scen serwisu (fullmovies 53 tys. + blowjob 555 tys.: 2-17 s, + # zgloszenie 80da1ce7). Wtedy sort po indeksie serwisu (origin_sort nizej), a tag + # jako zwykly filtr: blowjob 36 ms, rzadki tag z przejsciem calego serwisu ~0,1 s. + if origin and ":" in origin and not q: + from app.models.source_stats import SourceStats + + origin_scenes = session.execute( + select(SourceStats.scenes).where(SourceStats.origin == origin) + ).scalar() + if origin_scenes and origin_scenes < (smallest[2] or 0): + tag_sort_id = None for slug in tag_slug_list: tag_id = id_by_slug.get(slug) if tag_id is None: