Files
romm/backend/handler
Georges-Antoine Assi 2d140e606a fix(scan): consult sources from one rule table and keep stored matches on refresh (#5394)
* refactor(scan): decide which sources a scan consults from one rule table

Each of scan_rom's 16 provider fetchers opened with its own copy of the
same gate: is the source enabled, does it cover the platform, and does
this scan type (new, complete, update, unmatched, hashes) ask it about
this rom. The copies differed in small ways (which platform field,
whether a hash scan counts, whether an id alone counts as matched) that
were only visible by reading all 16 side by side.

RESCAN_RULES now holds one RescanRule per source, and should_consult
applies them. Each fetcher's gate is a single consults() call. The
fetchers' lookup logic is unchanged.

A brute-force comparison of the old inline gates against should_consult,
over 57,600 combinations of scan type, new rom, enabled source, id,
metadata, platform id and platform slug, found no differences. The new
test_scan_rescan_rules.py pins the rules per source without a database.

The nested fetchers drop from a combined cyclomatic complexity of 215 to
87 (437 to 264 lines).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(scan): pin rescan rule columns independently, cover Hasheous' platform id

Addresses Greptile's review: an explicit table of each rule's id and
metadata columns, Hasheous in the platform-id test, and a one-sentence
should_consult docstring.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(scan): keep stored matches on refresh and pick rescans from the rule table

- Every fetcher refetches a stored id through stored_match_id(): an update,
  or an unmatched retry of missing metadata, keeps the id instead of trading
  it for a hash or filename match. IGDB now prefers it over Hasheous and
  Playmatch, MobyGames and ScreenScraper refetch it on an unmatched retry, and
  Demozoo refetches it at all.
- Playmatch runs only when a source that reads its ids will be consulted.
- should_scan_rom picks update and unmatched roms with should_consult, so the
  platform gates and the metadata check apply, and Playmatch alone picks nothing.
- unmatched_supported takes the platform instead of reading rom.platform.
- scan_rom's handler table and update_rom's refetch table take their columns
  from RESCAN_RULES; a test checks METADATA_SOURCE_COLUMNS agrees with it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 15:03:01 -04:00
..