mirror of
https://github.com/rommapp/romm.git
synced 2026-11-28 17:48:31 +01:00
A smart collection re-ran its filters across the whole library on every request, loaded every match into memory with its joined metadata, wrote the membership back, and only then asked for the page being displayed. The cost tracked library size rather than collection size, was paid twice on first load and again on every scroll, and the write bumped updated_at, which the covers embed as a ?ts= cache-buster. Translate the stored filter_criteria into filter_roms keyword arguments and apply them to a bare Rom.id select instead, so membership stays in SQL and the database returns just the rows being rendered. The criteria vocabulary is filter_roms' own, so this composes with the gallery's filters. smart_collection_id is dropped from the criteria: the v2 create dialog records the route it was opened from, so a collection built while viewing another one carries its id, which would nest and could cycle. Bind parameters for the MATCH clauses are now named after the term they carry. A statement can hold two of them (the collection's search term and the gallery's), and SQLAlchemy does not uniquify explicitly named text() parameters, so a fixed name let one term overwrite the other. The cached rom_ids / rom_count / path_covers_* columns still back the collections list and the ROM detail page, so refresh them on write -- smart collection create and update, after a scan, and after ROMs are deleted -- rather than as a side effect of browsing. They are computed for the owner: the row is shared, so a per-user criterion like favorite would otherwise describe whoever opened the collection last. Regular collections and the favorites filter get the smaller half of the same treatment: an indexed subquery over collections_roms instead of an IN list built in Python. An unknown collection or smart collection now returns nothing rather than falling through to the entire library. Fixes #4029 AI assistance: implemented with Claude Code (Opus 5), tests first, then reviewed and verified by me. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>