Commit Graph

74 Commits

Author SHA1 Message Date
Georges-Antoine Assi
d62452b069 refactor: give the publisher/developer derivations one home
Follow-up cleanup on the company metadata split.

- Hasheous returns `involved_companies` keyed by id, not as the list IGDB
  itself returns, so iterating it yielded the dict's string keys and raised
  on `c.get("publisher")`. Read it through the same pydash accessor the
  sibling `companies` line uses, and cover both shapes with a test.
- ss/ra/flashpoint/gamelist bind the publisher and developer lists once and
  build `companies` from them, so the merged list cannot drift from the
  split it is meant to be the union of. Follows launchbox's existing shape.
- The exporters shared one copy of the "prefer the explicit field, fall back
  to the companies ordering" rule; it now lives on `RomMetadata` as
  `primary_developer` / `primary_publisher`.
- Migration 0112 gates its two backfills on a probe. No stored blob carries
  the new keys before a re-scan, so they otherwise scan the whole roms table
  twice, and rewrite every roms_facets row, to write nothing.
- Smart collections no longer claim a `selected_publisher` legacy key that
  never shipped.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-27 18:38:02 -04:00
Georges-Antoine Assi
42ebaaec49 feat: split company metadata into publishers and developers
Metadata providers (ScreenScraper, RetroAchievements, LaunchBox,
Flashpoint, gamelist, IGDB) distinguish the publisher from the developer
of a game, but RomM amalgamated both into a single `companies` list at
ingestion, so the distinction was unrecoverable. This adds `publishers`
and `developers` as new, refined fields end to end while keeping
`companies` (the merged union) working exactly as before.

Backend:
- Handlers now emit publishers/developers alongside the unchanged
  companies list; IGDB requests the involved_companies developer/
  publisher flags to split by role.
- Migration 0112 adds generated_publishers/generated_developers columns
  on roms, projects them through the roms_metadata view, mirrors them
  into roms_facets, and adds publisher/developer virtual-collection
  types (triggers/functions rebuilt for MariaDB/MySQL + PostgreSQL).
- Filters, facets, endpoints, smart collections and the gamelist/pegasus
  exporters all carry the new fields; exporters prefer the explicit
  split and fall back to the companies heuristic for un-rescanned ROMs.

Frontend (v2):
- Shared filter store + API service, gallery filter drawer, URL
  persistence, game detail display (Developers/Publishers with a
  Companies fallback), edit dialog, smart-collection criteria, and a
  publisher/developer "group virtual collections by" option.
- Also relabels the confusing "company"->"Developer" group-by option
  to "Company" now that a proper Developer option exists.

Fixes #3518

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-27 14:44:30 -04:00
Georges-Antoine Assi
bc95411239 feat: filter the gallery by physical games
Physical games were addable and visible but not selectable: nothing let a user
ask "what do I own on a shelf?" or exclude shelf entries from a view of what is
actually on disk.

Expose the handler's `physical` filter as a `GET /roms` query param and carry it
through the v2 gallery the way `filterSoundtrack` is carried: a tri-state row in
the filter drawer (all / physical only / file-backed only), the toolbar's active
count, `?filterPhysical=` in the URL so a filtered view stays bookmarkable, and
the smart-collection criteria plus their summary row.

Reuses mdi-cube-outline, already this feature's icon, with cube-off-outline as
the negative. Translated into all 18 locales, taking each one's existing term
for a physical game from rom.json.

Verified against the dev library (74898 roms): physical=1, file-backed=74897,
an exact partition, with the filtered gallery showing only the physical entry in
both themes and the control reachable by keyboard.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-27 11:01:47 -04:00
Georges-Antoine Assi
c951b6eb46 some clenaup 2026-08-01 14:49:58 -04:00
Spinnich
7399c19479 fix(collections): refresh smart collections on per-user state changes
Removing the read-time recompute left the cached membership blind to
everything that is not a ROM edit. A save, a state, a status, or moving
a ROM in or out of a regular collection all change what `has_saves`,
`has_states`, `statuses`, `collection_id` and `favorite` match, so the
stored counts, covers and ROM-detail chips went stale until an unrelated
edit or the next scan.

Refresh from those paths too: save and state upload, delete and
visibility toggle, `update_rom_user` when a status is set, and adding or
removing collection members. Sharing an asset is included because
`has_saves` matches other users' public saves, so it moves collections
that are not the uploader's.

These changes leave the ROM row alone, so they pass `membership_only`
and only recount a collection when the ROM actually joined or left.
Autosaves land constantly, and without it every one of them would force
a full recount of any collection the ROM already belonged to.

Reported by Greptile on #4039.

Implemented with Claude Code (Opus 5), tests first, then reviewed and
verified by me.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-31 22:18:53 +00:00
Spinnich
b5d276e2ed fix(collections): refresh smart collections per ROM, not per request
Recomputing every smart collection after a delete scanned the library
once per collection, synchronously on the event loop and inside a single
write transaction. Ask instead which of the changed ids each collection
matches: that resolves as a primary-key lookup, so only the collections
actually holding one of them pay for a recount.

Follow the same refresh into `update_rom` and the metadata reset. Both
change exactly the fields the saved filters match on, so cached counts
and cover mosaics no longer wait for the next scan to catch up.

Guard every call site. The ROM write is already committed by the time
the refresh runs, so a failure there must not be reported back as a
failed edit, and must not cost a bulk delete its per-ROM report.

Drop the handler-level test for leaving a collection untouched on read;
the endpoint test covers that invariant through the route the bug was
reported against.

Follow-up review of f4ac78c46 (#4029). Implemented with Claude Code
(Opus 5), then reviewed and verified by me.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-31 21:11:11 +00:00
Spinnich
f4ac78c46b perf(collections): serve smart collections from a composed query
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>
2026-07-31 20:23:31 +00:00
Georges-Antoine Assi
49d1ae71b2 Fix smart collections dropping newer filters
Smart collections silently ignored several filters at both ends:

- The backend never applied has_soundtrack, has_saves, has_states, or
  player_counts from stored criteria, so a "has soundtrack" smart
  collection contained every game. get_roms_scalar also dropped
  has_soundtrack before it reached filter_roms.
- The v2 criteria serializer had no fields for has_saves/has_states and
  only stored tri-state filters when true, so "unmatched" or "has
  saves" produced empty criteria and the no-filters guard blocked the
  save.

Criteria now carry saves/states filters and explicit false states, the
backend applies them, and summaries render negative states with the
existing "show-not-*" labels.

Fixes #3888

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-25 13:53:02 -04:00
Georges-Antoine Assi
93a128965b Merge pull request #3936 from Spinnich/fix/rom-detail-smart-collections
fix(roms): list the smart collections a ROM belongs to on its detail view
2026-07-24 21:38:13 -04:00
Spinnich
c6c80d8239 perf(roms): resolve smart-collection membership in SQL, not Python
The detail response listed a ROM's smart collections by loading every
own/public smart collection and scanning its cached rom_ids list in
Python. rom_ids grows with library size, so this got heavier on large
libraries on every detail load.

Push containment + visibility into the query via the existing cross-DB
json_array_contains_value helper (JSON_CONTAINS on MariaDB/MySQL, @>/?
on Postgres), returning only the matching rows with id/name/is_public.
The schema mapper no longer filters, so smart_for_user becomes the plain
from_smart_collections mapping. Behavior is unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-24 14:57:43 +00:00
Georges-Antoine Assi
91e098614e perf(backend): look up virtual collection covers per collection
_attach_covers ranked every membership row with a window function and
only then kept the first five per collection, so the collection list kept
a full scan proportional to library size (0.77s of a 0.92s list on a 50k
rom library) even though the view lookup itself is now indexed.

Each collection instead gets its own primary-key lookup capped at
MAX_VIRTUAL_COLLECTION_COVERS, batched into UNION ALL statements, so the
cost follows the number of collections. The covers returned are
unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-22 21:52:59 -04:00
Georges-Antoine Assi
753556af7b perf(backend): materialize virtual collection membership
virtual_collections was a view that unnested five JSON arrays per rom on
every read, so both the collection list and opening a single collection
scanned the whole library. Opening a collection with a handful of roms
cost as much as one with thousands, since the name is computed inside the
view and nothing can be narrowed down early.

Membership now lives in virtual_collection_roms, one narrow row per
(type, name, rom_id) plus that rom's covers, derived from the generated_*
columns and maintained by triggers on roms (deletions ride the foreign
key cascade). The view becomes a plain aggregate over that table, so the
model, schemas and API shape are unchanged, and filtering roms by a
virtual collection is an indexed subquery instead of an IN list of every
member id.

Covers are no longer aggregated in the view, which materialized every
member's cover path on every request; the handler resolves at most five
per collection, matching the smart collection cap and what both UIs
render.

On a synthetic 50k-rom library the list goes from 1.42s to 0.128s and a
single collection from 0.111s to 0.0006s, with identical output.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-22 10:06:05 -04:00
Spinnich
14a0a98661 feat(roms): filter games by custom tags
Adds a "Tag" gallery filter so a library can be narrowed by the custom
tags parsed from filenames (No-Intro / Redump nomenclature, e.g. Proto,
Beta, Demo), mirroring the existing data-derived multi-value filters
(regions, languages). Closes #3546.

Backend:
- New `_filter_by_tags` over `Rom.tags` with any/all/none logic; wired
  through filter_roms, get_roms_scalar, the /roms endpoint (tags +
  tags_logic), and the unscoped cache gate.
- Tags are data-derived, so the selectable list is surfaced via
  filter_values: added to _collect_filter_values, with_filter_values,
  get_rom_filters, and RomFiltersDict.
- Smart collections apply the criterion via get_smart_collection_roms.

Frontend (v1 + v2):
- Wired into the galleryFilter store, rom API service, request cache key,
  both filter drawers, v2 URL persistence, the v2 refetch watcher, and
  smart-collection serialization/summary + create dialog.
- Added the `platform.tag` key to all locales (distinct from the existing
  `platform.tags` section heading).

Tests:
- Backend handler (any/all/none + unknown-value), endpoint, filter_values,
  and smart-collection coverage.
- Frontend smartCollectionCriteria serialization/summary coverage.

AI assistance: implemented with Claude Code (Anthropic).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-29 11:29:12 +00:00
Spinnich
d546165814 style: normalize collections_handler.py to LF line endings
This was the only CRLF-encoded file in the backend; every other Python
source uses LF. The earlier minimal-diff workaround left it mixed, so
convert it fully to LF (the repo standard) for internal consistency.

No logic changes in this commit. The only behavioural change to this file
in the PR remains the two lines added to get_smart_collection_roms
(metadata_providers + metadata_providers_logic).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-29 10:44:54 +00:00
Spinnich
345a690c82 refactor(roms): deduplicate metadata-provider definitions (PR review)
Addresses review feedback on #3615:

- Backend: merge the new filter column map with stats_handler's
  `_METADATA_SOURCE_COLUMNS` into a single `METADATA_SOURCE_COLUMNS` in
  models/rom.py, imported by both. It's the union of the two prior sets,
  so the stats coverage breakdown now also reports `libretro`.
- Frontend: drop the duplicated provider list from utils; derive the
  filter options from the `METADATA_PROVIDERS` registry via
  `METADATA_PROVIDER_FILTER_OPTIONS` (added a `name` brand field). Both
  filter drawers import from the registry now.
- collections_handler.py: revert the stray CRLF->LF normalization so the
  diff is just the two smart-collection lines.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-29 10:35:59 +00:00
Spinnich
983f016efe feat(roms): filter games by matched metadata provider
Adds a "Metadata provider" gallery filter so a library can be narrowed by
which providers each ROM matched (IGDB, MobyGames, ScreenScraper, etc.),
mirroring the existing multi-value filters (player count, age rating).

Backend:
- New `_filter_by_metadata_providers` keyed off each provider's id column
  on Rom, with any/all/none logic; wired through filter_roms,
  get_roms_scalar, the /roms endpoint, and the unscoped cache gate.
- Smart collections apply the criterion via get_smart_collection_roms.
- Unknown provider slugs are ignored (no-op) so stale bookmarks or
  hand-edited URLs don't error.

Frontend (v1 + v2):
- Shared METADATA_PROVIDER_OPTIONS registry; provider list is a fixed set
  rather than data-derived, so options are static.
- Wired into the galleryFilter store, rom API service, request cache key,
  both filter drawers, v2 URL persistence, the v2 refetch watcher, and
  smart-collection serialization/summary.
- Added the `platform.metadata-provider` key to all locales.

Tests:
- Backend handler, endpoint, and smart-collection coverage (any/all/none
  plus unknown-slug).
- Frontend smartCollectionCriteria serialization/summary coverage.

Also normalized collections_handler.py to LF (it was the only CRLF file in
the backend, which tripped git-diff-check on the edited lines).

AI assistance: implemented with Claude Code (Anthropic).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-26 13:52:19 +00:00
copilot-swe-agent[bot]
7ab4052f93 Fix legacy smart collection status list normalization
Co-authored-by: gantoine <3247106+gantoine@users.noreply.github.com>
2026-06-08 12:25:56 +00:00
Spinnich
15b485b118 fix(collections): address reviewer feedback on types and concurrency
- Use CollectionSchema instead of ReturnType<typeof collectionsStore.getCollection>
  in AddRoms.vue and RemoveRoms.vue (simpler, per gantoine review)
- Wrap bulk INSERT in a savepoint so a concurrent duplicate-key violation
  is caught via IntegrityError and ignored rather than aborting the transaction
- Only bump Collection.updated_at in remove_roms_from_collection when rows
  were actually deleted (rowcount > 0), matching add_roms_to_collection behavior

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-15 06:46:12 -04:00
Spinnich
2ecefa3d3f Fix race condition in collection and favorite rom membership updates
Replace full rom_ids list replacement with atomic POST/DELETE endpoints
that add or remove individual ROMs from a collection. This prevents
concurrent rapid clicks from overwriting each other (last-write-wins).

Also fix missing session.flush() in add_rom_user() and add collection
endpoint tests.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-14 15:08:53 -04:00
Georges-Antoine Assi
a3ebe16a39 run fmt 2026-03-24 15:32:48 -04:00
copilot-swe-agent[bot]
a5954590ec Fix IntegrityError when updating favourites with stale ROM IDs
Co-authored-by: gantoine <3247106+gantoine@users.noreply.github.com>
Agent-Logs-Url: https://github.com/rommapp/romm/sessions/8a6fd3fe-77ab-4f7b-a0e9-1c55e7096e88
2026-03-23 22:19:06 +00:00
Georges-Antoine Assi
bddb7bd9f5 manual cleanup 2026-01-18 22:27:46 -05:00
Georges-Antoine Assi
3ccc14d4a2 add endpoints for identifiers 2026-01-18 22:17:37 -05:00
Georges-Antoine Assi
54bfb3fec5 DB functions accept list of params 2026-01-18 21:26:48 -05:00
Brandon T. Kowalski
5cb71c920f Added updated_after query parameter for normal and smart collections and migration to add corresponding indexes to each table. 2026-01-17 23:25:02 -05:00
Georges-Antoine Assi
3965a89860 convert legacy selected_status 2026-01-14 11:05:43 -05:00
Georges-Antoine Assi
2d8444d60b [HOTFIX] Rename selected_statuses to statuses 2026-01-14 10:07:57 -05:00
zurdi
a956008259 feat: update ROM filtering to support multi-value statuses and logic operators 2025-12-25 11:52:00 +00:00
zurdi
48d6df9cc0 feat: add logic operators for multi-value filters in collections and roms handlers 2025-12-24 15:23:44 +00:00
zurdi
ab637203ac Merge branch 'master' into feat/rom-filter-multivalue 2025-12-24 12:39:45 +00:00
Georges-Antoine Assi
19ef2d4d5f type ignore session and query attrs 2025-12-12 17:05:12 -05:00
zurdi
bc73f07537 Refactor: enhance filter criteria handling to support multi-value selections for genres, franchises, collections, companies, age ratings, regions, and languages 2025-11-28 22:36:21 +00:00
zurdi
92cb643405 Refactor: update filter criteria handling to support multi-value platform IDs and remove legacy conversion logic 2025-11-28 17:04:43 +00:00
zurdi
c1d43f67f8 Refactor ROM retrieval to support multi-value platform filtering across various handlers and endpoints 2025-11-27 22:52:33 +00:00
zurdi
c6717ee635 Refactor gallery filter components to use toggle buttons for filter states, allowing null values for all filters. Update filter logic in the store and API services to accommodate new states. Enhance UI for better visibility and interaction with filter options in the gallery app. 2025-11-27 12:56:01 +00:00
zurdi
d48be2f37c Merge branch 'master' into feat/rom-filter-multivalue 2025-11-21 14:11:07 +00:00
Georges-Antoine Assi
1c84f84948 globally rename favourite to favorite 2025-10-18 14:26:20 -04:00
Georges-Antoine Assi
341332d98e mark favorites collection explicit 2025-10-18 13:42:03 -04:00
Michael Manganiello
5a1f7d8170 feat: Initial support for multi-value ROM filters
This change converts the existing single-value ROM filter parameters
to support multiple values. Users can now filter ROMs by multiple genres,
franchises, collections, companies, age ratings, regions, and languages by
repeating the respective query parameters in API requests.

At the moment, setting multiple values for a filter will return ROMs
that match any of the provided values (logical OR). A future change can
introduce parameters like `genres_all (boolean)` to allow filtering ROMs
that match all specified values (logical AND).

The frontend has been updated to send single-value filters as arrays
to maintain compatibility with existing UI components. At the moment,
the UI does not support selecting multiple values, but this change
lays the groundwork for it.

NOTE: Breaking API change, as the filter parameters have changed names.
2025-09-09 00:21:55 -03:00
Michael Manganiello
e4e3928d1b misc: Apply import sorting 2025-09-04 11:17:00 -03:00
Georges-Antoine Assi
898f960c96 noload rom metadata on collection 2025-08-22 09:15:03 -04:00
Georges-Antoine Assi
b26abdf9a0 noload some related tables 2025-08-21 23:59:24 -04:00
Georges-Antoine Assi
344702415f joinedload roms on collection 2025-08-21 23:23:38 -04:00
Georges-Antoine Assi
7850cf059f fix loading collections 2025-08-19 21:49:52 -04:00
Georges-Antoine Assi
2a8fec94e6 update smart collection model 2025-07-25 16:27:10 -04:00
Georges-Antoine Assi
f7b030ba10 get backend working sorta 2025-07-22 18:10:12 -04:00
Georges-Antoine Assi
75b8181451 start work on smart collections 2025-07-22 15:49:43 -04:00
Michael Manganiello
252722e3bc misc: Apply pyupgrade changes for Python 3.12 compatibility
Command applied:
```
find ./backend/ -type f -name "*.py" -exec pyupgrade --py312-plus {} \;
```
2025-06-29 12:27:16 -03:00
Georges-Antoine Assi
1cb66e28ec fix removing game from collection 2025-02-27 11:21:51 -05:00
Georges-Antoine Assi
3088e4566c changes from self-view 2025-02-09 11:22:10 -05:00