Commit Graph

9 Commits

Author SHA1 Message Date
Georges-Antoine Assi
b35eb4d07c fix(scan): clean up unreferenced rescan media, split scan_rom and move its parts into handler/scan (#5408)
* fix(scan): delete screenshots and media a rescan leaves unreferenced

A complete rescan keeps the stored artwork, so two kinds of file stayed on
disk with nothing pointing at them:

- screenshots indexed past a shorter new list, since files are named by
  position and only the indexes in range were rewritten
- media of a type removed from the preferences, since providers record no
  path for it and stale media was compared over the preferred types only

get_rom_screenshots now deletes the indexes past the new list, and
remove_stale_media compares every media type.

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

* refactor(scan): split scan_rom's merge into named steps

scan_rom held seeding the row, following Demozoo links, splicing scene
summaries, resetting rematched sources, the scene lock, rehash cleanup,
priority merges for fields, tags and artwork, and the SteamGridDB pass in one
body. Each step is now its own helper, the SteamGridDB lookup a _RomLookups
method, and the providers' answers a dict keyed by source instead of fourteen
locals. The Pouet and CSDb link follows share one helper. Behaviour is
unchanged.

McCabe complexity of scan_rom goes from 68 to 13, and the function from 664
to 215 lines.

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

* fix(scan): trim remove_stale_media's docstring per Greptile review

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

* refactor(scan): move the scan vocabulary, lookups and merge into handler/scan

scan_handler.py held the scan types and metadata sources, the per-source
lookups, the merge of their answers and the orchestration in one 2,000-line
module. It now builds on a handler/scan package:

- sources.py: ScanType, MetadataSource, the tag constants, RESCAN_RULES,
  should_consult, stored_match_id and the priority ordering
- lookups.py: RomLookups, the LaunchBox and Steam resolvers and
  get_main_platform_igdb_id
- merge.py: the pure steps that merge the sources' answers into a rom's
  columns

scan_handler.py keeps scan_platform, scan_rom, the asset scans and the media
downloads. Importers point at the module that now defines each name, and the
helpers that crossed a module boundary lost their leading underscore.
clear_rehash_misses takes the attempted sources instead of the lookups, so
merge does not depend on lookups. Behaviour is unchanged.

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

* fix(ci): import ScanType from handler.scan.sources in the e2e seed script

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

* fix(scan): harden leftover screenshot cleanup (pr-ready: code-review)

List the screenshots folder once, use isdecimal() for the index test, and
log rather than raise when a leftover can't be removed. Point three
comments at handler/scan instead of scan_handler.

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

* refactor(scan): tidy the merge helpers and patch paths (pr-ready: simplify)

- fetch_sgdb_rom refetches by stored_id and builds the SGDB name list
  itself, so the name sources stay private to lookups.
- follow_demozoo_link checks the source is enabled; scan_rom loops over
  Pouët and CSDb.
- order_merge_sources holds the one ordering pass, and
  build_metadata_handlers adds the empty SGDB entry.
- Leftover screenshots go through the quiet-delete helper, renamed
  _discard_file.
- Tests patch rom lookups through handler.scan.lookups.

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

* fix(scan): never leave a recorded media or screenshot path without its file

- remove_stale_media only deletes a file whose owner or source changed
  when that new owner stores the type again in this pass. A file nothing
  records is still deleted.
- Screenshots past a shorter list are pruned by remove_screenshots_past
  once the new paths are saved, in both download_rom_resources and
  update_rom, so a failed cover or manual leaves them in place.
- The release-notes schema diff watches scan_handler.py beside
  scan/sources.py, for ranges that span the move.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 15:23:13 -04:00
Claude
dd3b0a6f99 perf: stop loading the auth and web stack in background processes
Importing any handler.auth submodule ran the package __init__, which
built the auth handlers and so loaded authlib, joserfc and Socket.IO.
models.user imports handler.auth.constants, so every process that
touched the models paid for the whole auth stack. The handler
instances now live next to their classes in handler.auth.base_handler.

utils.context imported fastapi only for annotations; that import now
sits under TYPE_CHECKING.

An idle RQ worker drops from about 118 MB to 89 MB RSS. Each job's
forked work horse now imports a little more on its own, about 0.2s
on an x86 host.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gh1SRMfuK7BZmf6YxMqSyT
2026-10-01 01:02:37 +00:00
Georges-Antoine Assi
5cad653261 fix(auth): look up seeded permission groups by a stable system key
Tests, fixtures and the e2e seed found the seeded groups by display name,
which an admin can edit and this PR just changed. A unique system_key
column (viewer/editor), added and backfilled by 0137, identifies them
instead, and get_system_group() replaces the name lookups.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-26 10:42:44 -04:00
Georges-Antoine Assi
3068ae9d97 refactor(auth): simplify group rename migration and e2e seed lookup (simplify)
The e2e seed resolves the viewer via get_default_group instead of a list
of fallback names. The migration drops the id pre-select, and the tests
load the revision once and call upgrade/downgrade directly.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-26 10:32:36 -04:00
Georges-Antoine Assi
f3e045196f fix(auth): renumber group rename migration to 0137 (code-review)
Master already chains 0135 and 0136 onto 0134, so the rename becomes
0137 revising 0136_deleted_assets to keep a single alembic head. Also
dedupe the migration filename in tests, rename tests that still said
legacy, and drop em-dashes and a long docstring.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-26 10:30:17 -04:00
Sam Dornan
bb5d210530 fix(auth): find the seeded Viewer by system flag in the e2e seed
Address Greptile review: the e2e seed could pick an admin-created "Viewer"
group, the migration docstring recounted history, and the conflict test
compared a description with itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xdb9FnfhEqP6ectkSZ2T3F
2026-09-25 00:50:30 +00:00
Sam Dornan
86fa809612 fix(auth): rename seeded permission groups to Viewer and Editor
Every install showed "Viewer (legacy)" and "Editor (legacy)" as the built-in
groups, which reads as deprecated. 0092 already shipped in 5.3.0, so a new
revision renames the untouched system rows and drops the "pre-upgrade"
framing from their descriptions. It skips a group whose target name an admin
already took, and keeps a description the admin edited.

Fixes #4678

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xdb9FnfhEqP6ectkSZ2T3F
2026-09-25 00:36:34 +00:00
Georges-Antoine Assi
7ceef7647a cleanup 2026-07-26 13:17:42 -04:00
Georges-Antoine Assi
474ef5b6e8 Move the e2e seed scripts to .github/scripts
They exist to stand up a disposable instance for the Playwright suite, so
they belong with the workflow that runs them rather than in backend/tools/
next to the library-generation utilities.

Their sys.path bootstrap now points at backend/ explicitly (it relied on
being one level below it), the workflow invokes them from the repo root
instead of backend/, and .github/scripts/** joins the workflow's path
filters so editing a seeder still triggers the suite.
2026-07-26 13:05:54 -04:00