fix: don't re-stamp updated_at for unchanged ROMs during scans

bulk_mark_present issued an unconditional UPDATE setting missing_from_fs=False
on every matched row, including rows already present. Since Rom.updated_at has
onupdate=utc_now, every scan re-stamped all skipped/unchanged ROMs of a
platform, defeating updated_after-based incremental consumers and busting every
cover URL (?ts={updated_at}) on each scan.

Mirror the missing-side guard (mark_missing_roms) by restricting the UPDATE to
rows that actually flip via Rom.missing_from_fs.is_(True), so an unchanged
platform issues no updates.

Fixes #3836

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Georges-Antoine Assi
2026-07-19 21:56:00 -04:00
parent a62ff66ffb
commit 8df91d1c99
2 changed files with 54 additions and 1 deletions

View File

@@ -1533,7 +1533,12 @@ class DBRomsHandler(DBBaseHandler):
rom_ids: list[int],
session: Session = None, # type: ignore
) -> None:
"""Bulk set missing_from_fs=False for a list of ROM IDs."""
"""Bulk set missing_from_fs=False for a list of ROM IDs.
Only rows that actually flip are written, so a re-scan of an
unchanged platform issues no updates and leaves `updated_at`
untouched, keeping it a usable incremental signal.
"""
if not rom_ids:
return
@@ -1545,6 +1550,7 @@ class DBRomsHandler(DBBaseHandler):
and_(
Rom.platform_id == platform_id,
Rom.id.in_(chunk),
Rom.missing_from_fs.is_(True),
)
)
.values(missing_from_fs=False)

View File

@@ -492,6 +492,53 @@ def test_bulk_mark_present(platform: Platform):
assert updated.missing_from_fs is True
def test_bulk_mark_present_skips_already_present(platform: Platform):
"""bulk_mark_present leaves updated_at untouched for already-present ROMs.
Regression: an unchanged (already present) ROM must not be re-stamped on
each scan, so `updated_after`-based incremental consumers stay usable.
"""
present = db_rom_handler.add_rom(
Rom(
platform_id=platform.id,
name="rom_present",
slug="rom-present",
fs_name="rom_present.zip",
fs_name_no_tags="rom_present",
fs_name_no_ext="rom_present",
fs_extension="zip",
fs_path=f"{platform.slug}/roms",
missing_from_fs=False,
)
)
missing = db_rom_handler.add_rom(
Rom(
platform_id=platform.id,
name="rom_missing",
slug="rom-missing",
fs_name="rom_missing.zip",
fs_name_no_tags="rom_missing",
fs_name_no_ext="rom_missing",
fs_extension="zip",
fs_path=f"{platform.slug}/roms",
missing_from_fs=True,
)
)
present_updated_at = db_rom_handler.get_rom(present.id).updated_at
db_rom_handler.bulk_mark_present(platform.id, [present.id, missing.id])
# Already-present ROM is not re-stamped.
present_after = db_rom_handler.get_rom(present.id)
assert present_after.missing_from_fs is False
assert present_after.updated_at == present_updated_at
# Actually-missing ROM is flipped to present.
missing_after = db_rom_handler.get_rom(missing.id)
assert missing_after.missing_from_fs is False
def test_bulk_mark_present_empty_list(platform: Platform):
"""bulk_mark_present with an empty list is a no-op."""
rom = db_rom_handler.add_rom(