Commit Graph

11013 Commits

Author SHA1 Message Date
Georges-Antoine Assi
440cc6fa2d docs(roms): drop two redundant comments
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-30 14:58:42 -04:00
Spinnich
0526ded376 test(roms): drop the tautological index assertion
Asserting the model declares the index only restates `models/rom.py`. The
migration test covers what matters: the index exists in a database the
migrations built. Also pin the predicate test to the literal it compiles
to, so an unrelated `IS NOT NULL` elsewhere in the query cannot fail it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-30 14:24:21 +00:00
Spinnich
fdb000576a perf(roms): stop the Missing tab scanning the whole library
Settings -> Library Management -> Missing made three whole-library passes
per request, two of which produced data the page never renders, and none
of which could be cached because "missing" counts as a filter.

- The tab now opts out of the char index, the filter values and the
  ordered id index, so the endpoint serves its total from a plain COUNT.
- `missing_from_fs` gets a composite index with `name_sort_key`, and the
  filter compiles to an equality: MariaDB does not treat `IS NOT FALSE`
  as indexable, so the index would otherwise only ever be scanned end to
  end. The column is NOT NULL, so both forms match the same rows.
- The filter-value list is keyed on the scope (search / platform /
  collection) alone. It is built from a query that never applies the
  row-level filters, so a filtered request now answers with, and warms,
  the same whole-library entry an unfiltered one does.

Fixes #3992

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-30 12:13:03 +00:00
Georges-Antoine Assi
06cafd4b10 fix cron_string in update_switch_titledb 5.1.0 2026-07-29 17:41:52 -04:00
Georges-Antoine Assi
443c796f1e reduce freegosy text 2026-07-29 16:55:22 -04:00
Georges-Antoine Assi
ff8d4d0d5d Merge pull request #3986 from rommapp/fix/launchbox-cloud-empty-store
fix(launchbox): stop the cloud provider from silently matching nothing
2026-07-28 23:09:10 -04:00
Georges-Antoine Assi
57f4fd21d0 cleanup 2026-07-28 23:01:07 -04:00
Georges-Antoine Assi
49f2b48f5f Merge pull request #3987 from rommapp/fix/gallery-placeholder-row-overflow
fix(gallery): pack placeholder covers at the active boxart ratio
2026-07-28 22:57:39 -04:00
Georges-Antoine Assi
e8aa2f5afd fix(gallery): pack placeholder covers at the active boxart ratio
The grid flow-packs rows in JS from each card's real width
(cardHeight * coverRatio), and rows render nowrap with flex-shrink: 0 —
so an underestimated width overflows the viewport instead of wrapping.
Ratios are measured on cover load, but a rom with no cover paints its
placeholder at the boxart style's ratio and never measures, so the
packer's hardcoded 2/3 under-reserved its width and let an extra card
into the row.

The packer now takes the style ratio as its fallback for any position
without a measured cover, which also covers the pre-load paint of every
card in a non-2/3 gallery.

Fixes #3984

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-28 22:36:39 -04:00
Georges-Antoine Assi
ad07bafbd1 fix(tasks): load the task list when the tasks page opens
The list was fetched once at app boot, inside a bootstrap that runs
before anyone is logged in. /tasks needs the tasks.run scope, so any
session established after boot (any login without a reload) left the
watcher, scheduled and manual lists empty for the rest of the page load,
in both UIs. For a logged-in non-admin the same call 403'd on every page
load and tripped the interceptor's redirect to login.

Fetch on mount from the pages that need it instead.

Fixes #3981

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-28 22:22:13 -04:00
Georges-Antoine Assi
8c12ac86a1 fix(launchbox): keep the heartbeat honest during a first import
The store is written in batches, so an initial import answers for the
names committed so far long before it holds the whole dump. Checking
that the name index exists reported the provider healthy off a fraction
of the entries, and a run that died partway left it that way for good.

Flag the initial import and clear it once a run completes, so only a
finished import counts as healthy. A refresh keeps serving the previous
dump, so it is not flagged.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-28 22:22:06 -04:00
Georges-Antoine Assi
963e4cab48 Merge pull request #3983 from rommapp/fix/valkey-snapshot-write-amplification
fix(docker): stop valkey rewriting its whole RDB every few minutes
2026-07-28 22:02:39 -04:00
Georges-Antoine Assi
f4984fb218 cleanup 2026-07-28 21:28:09 -04:00
Georges-Antoine Assi
7f0636aed5 Apply suggestion from @greptile-apps[bot]
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
2026-07-28 21:26:15 -04:00
Georges-Antoine Assi
79a64c473e Merge pull request #3982 from rommapp/fix/platforms-index-hide-empty
fix(platforms): hide empty platforms behind a toolbar filter
2026-07-28 21:06:13 -04:00
Georges-Antoine Assi
85351739e8 fix(platforms): use a clearer icon for the include-empty filter
mdi-select-all is a marquee-selection glyph, so it read as an action
rather than a filter state. mdi-asterisk carries the wildcard
"everything" meaning the segment actually has.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-28 20:11:09 -04:00
Georges-Antoine Assi
52940ea3d4 fix(launchbox): stop the cloud provider from silently matching nothing
LaunchBox cloud lookups read from a Redis store that only the metadata
update task fills, but nothing surfaced when that store was empty. The
provider reported healthy, every search returned zero results, and the
logs said nothing.

- heartbeat now reports unhealthy until the store is populated, and an
  empty store logs what to set to fix it
- the update task can be run manually whenever LAUNCHBOX_API_ENABLED is
  on, instead of also requiring the scheduled-update flag
- the ~600k entry dump was buffered into a single pipeline, peaking at
  1.7GB of RSS and writing nothing at all if the job was killed part way
  through. Writes now go out in batches and parsed elements are dropped
  as they are consumed, which caps the run at ~260MB. The task also gets
  its own timeout, since the default 5 minutes does not cover a 100MB
  download plus a 500MB parse
- alternate name lookups ignored the platform, so "Super Mario World" on
  PlayStation matched Super Mario Bros.
- Coleco ADAM was spelled wrong, and Famicom / Super Famicom pointed at
  platform names LaunchBox does not use

Fixes #3981

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-28 19:55:16 -04:00
Georges-Antoine Assi
ae46dc64c2 fix(tasks): make the upload tmp cleanup importable by the RQ worker
Importing the task module first, as the worker does when it resolves the job,
pulled endpoints.roms in and closed an import cycle through decorators.database.
RQ hides the ImportError behind "Invalid attribute name: run", so the cleanup
never ran and orphaned chunked-upload directories piled up.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-28 18:41:51 -04:00
Georges-Antoine Assi
48259b3a9e fix(docker): snapshot the internal valkey hourly instead of every few minutes
The keyspace holds the Switch TitleDB and LaunchBox caches, so dump.rdb runs
to hundreds of MB (424MB on a dev instance). Valkey's stock save policy
rewrites all of it every ~5 minutes once 100 keys change, which idle RQ
bookkeeping alone triggers, for gigabytes of disk writes per hour.

Fixes #3980

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-28 18:41:49 -04:00
Georges-Antoine Assi
8abd192163 fix(v2): batch URL query writes so concurrent toolbar filters don't stomp
`router.replace` is async, so `route.query` keeps reading the pre-navigation
value. Two URL-backed controls changing in the same flush each built their
next query from that stale snapshot, and the second navigation won with a
query that never saw the first one's key.

Reachable today on the Collections index: picking the "virtual" kind also
clears the visibility filter in the same flush, and the clear dropped
`?kind=virtual`.

Route every writer (search, view mode, Platforms and Collections filters)
through `patchQuery`, which merges patches and issues one navigation per
tick.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-28 18:41:15 -04:00
Georges-Antoine Assi
ba83af5caf fix(platforms): hide empty platforms behind a toolbar filter
The Platforms index switched to allPlatforms, so every leftover 0-game
platform row rendered in the grid, burying real libraries under hundreds
of stubs.

Empty platforms are hidden again by default and surface through a new
segmented toolbar cluster, URL-synced as ?show=all. They stay reachable
(and deletable) that way, so they don't become stranded in the database
again.

Fixes #3979

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-28 18:32:44 -04:00
Georges-Antoine Assi
81d740c5bd Merge pull request #3976 from rommapp/fix/rom-artwork-nested-game-media
fix(frontend): only treat top-level game folder files as media assets
2026-07-28 18:20:11 -04:00
Georges-Antoine Assi
345610afad Merge pull request #3974 from XenuIsWatching/fix/scan-concurrency-and-stop
fix(scan): refuse concurrent scans and stop queued ones
2026-07-28 18:19:48 -04:00
Georges-Antoine Assi
ead93451a1 Merge pull request #3973 from seffignoz/fix/v2-emulatorjs-full-navigation
fix(v2): use full document navigation for EmulatorJS player
2026-07-28 18:01:24 -04:00
Georges-Antoine Assi
fecd5b7c75 Merge pull request #3972 from XenuIsWatching/perf/orphaned-cleanup-scandir
perf(tasks): walk resource directories with os.scandir
2026-07-28 18:00:51 -04:00
Ryan McClelland
903df17f6e fix(scan): detect scans on every queue and entry point
Scan job discovery only looked at the high priority queue and only
recognised scan_platforms, so two kinds of in-flight scan went unseen.

Watcher scans are delayed through the scheduler and land in the low
priority queue, so the concurrency guard let a manual scan start
alongside one and the stop handler left it queued to run afterwards.

The scheduled rescan enqueues its own task and calls scan_platforms in
process, so the worker reports the task's name. That made stopping it a
silent no-op: with no running job matched, the stop flag it polls was
never set.

Discovery now spans both queues plus the scheduler and matches either
function name. The scheduler registry also holds the standing cron entry
for the scheduled rescan, which is a schedule rather than a pending
scan, so only delayed scan_platforms jobs count as queued.

Clearing the stop flag at scan start is now scoped to the scan that owns
it, so a scan starting next to one that has not yet polled the flag
cannot drop a stop request meant for it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-28 12:47:31 -07:00
Georges-Antoine Assi
1598c3ac69 fix(frontend): only treat top-level game folder files as media assets
The v2 details view scooped every image/video inside a multi-file ROM
folder into the artwork resolver, so a Wii U dump shipping cutscenes as
content/Movie/*.mp4 rendered dozens of <video preload="metadata">
elements at once. The resulting burst of Range requests saturated the
backend and hung the page for minutes.

Library media now has to sit at the top level of the game folder, which
is what "a trailer or artwork dropped next to the ROM" meant all along.
Nested files are game data; nested assets that are genuinely media
(screenshots, soundtrack, manual) already have their own surface via
their category.

Fixes #3975

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-28 09:15:16 -04:00
Ryan McClelland
99e214a8b4 fix(scan): refuse concurrent scans and stop queued ones
`scan_handler` enqueued a scan on every request without checking whether
one was already running. A client that lost the progress socket, which
happens routinely on mobile when the tab is backgrounded, has no way to
tell a scan is still in flight, so pressing scan again looks reasonable
and silently queues a second full library scan behind the first. Three
scans of the same library ran back to back on a real instance this way.

Reject the request instead, reusing the `scan:done_ko` channel that
`reject_unauthorized_scan` already uses to report a refused scan.

`stop_scan_handler` only ever cancelled the running job, so the queued
duplicates it left behind started as soon as it stopped. It now cancels
queued scans as well.

Its first lookup loop was also dead: it searched `high_prio_queue` for a
job named `scan_platform` with `is_started` set, but RQ records the name
as `endpoints.sockets.scan.scan_platforms`, and a started job is no
longer in the queue. The second loop hardcoded the full path, which is
what the first one drifted away from, so both lookups now derive the
name from the function object and are shared with the new guard.

Finally, clear the stop flag when a scan starts. It is only cleared by
the scan that observes it, so a stop requested against a scan that ended
first would leave the flag set and abort the next scan before it began.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-27 17:53:51 -07:00
seffignoz
f2161609e7 fix(v2): reload document for EmulatorJS player 2026-07-27 19:44:10 -04:00
Ryan McClelland
4bf8f5a15c perf(tasks): walk resource directories with os.scandir
The orphaned resource cleanup listed the resource tree through
`anyio.Path`, which dispatches to a worker thread for every entry it
yields and again for every `is_dir()` call. On a library with ~30k ROM
resource directories that is ~60k thread round trips to read data the
directory listing already contains.

Measured on a 30,262-directory library (Raspberry Pi 4, ext4):

    anyio iterdir + is_dir()   50.3s
    os.scandir                  0.15s

`os.scandir` reports the entry type from the directory read itself, so
no per-entry stat is needed. The walk moves into a helper run once via
`asyncio.to_thread`, keeping the event loop free while doing the whole
traversal in a single thread hop rather than tens of thousands.

Cold and warm runs of the old code were within 1% of each other, so this
was thread-dispatch overhead rather than disk I/O.

A directory that cannot be listed now logs and yields an empty set
instead of aborting the walk, so one unreadable platform cannot strand
every other platform's orphans.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-27 15:48:30 -07:00
Georges-Antoine Assi
4b83bf0e5d Merge pull request #3971 from rommapp/fix/orphaned-cleanup-empty-db-guard
fix(tasks): skip orphaned resource cleanup when the database looks empty
5.1.0-beta.3
2026-07-27 18:15:24 -04:00
Georges-Antoine Assi
7409535da7 Merge pull request #3969 from XenuIsWatching/fix/resources-enospc-handling
fix(resources): handle write failures when the disk is full
2026-07-27 18:14:51 -04:00
Georges-Antoine Assi
74d1d1ad9e Merge pull request #3966 from rommapp/fix/fpkgi-multi-file-entries
Serve each PKG file as its own FPKGi entry
2026-07-27 18:07:03 -04:00
Georges-Antoine Assi
e885792aa1 fix(tasks): skip orphaned resource cleanup when the database looks empty
`cleanup_orphaned_resources` decides what to delete purely by asking whether
a resource directory's id is absent from the database, with no sanity floor.
If `get_platforms()` ever comes back empty while artwork is still on disk
(database unavailable, mid-migration, half-restored backup), every platform
directory is treated as orphaned and removed in a single pass.

That was tolerable when the task only ran on an admin's click. Now that it
can run unattended at 5 AM via `ENABLE_SCHEDULED_CLEANUP_ORPHANED_RESOURCES`,
nobody is watching when it happens.

Bail out when the database reports zero platforms but platform directories
exist on disk, and log a warning saying so. A genuinely emptied library can
still be cleaned by running the task manually with `{"force": true}`, which
the run-task endpoint already forwards to `run()`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-27 17:06:28 -04:00
Georges-Antoine Assi
c9f7266b0e Merge pull request #3970 from XenuIsWatching/feat/scheduled-orphaned-resources-cleanup
feat(tasks): allow orphaned resource cleanup to run on a schedule
2026-07-27 17:02:06 -04:00
Georges-Antoine Assi
bd18af8efa cleanup 2026-07-27 16:54:52 -04:00
Ryan McClelland
90d1c72256 feat(tasks): allow orphaned resource cleanup to run on a schedule
Orphaned covers and screenshots left behind by deleted ROMs accumulate
indefinitely, because the only way to reclaim them is to trigger the
cleanup task by hand. On a long-lived instance the resources directory
grows without bound, which is a problem when it shares a filesystem with
the database.

Move the task to `tasks/scheduled/` and turn it into a `PeriodicTask`
with an opt-in cron schedule, defaulting to 5:00 AM so it runs after the
nightly scan and metadata tasks have settled.

`enabled` stays `True` rather than tracking the new env var, because the
run-task endpoint requires both `enabled` and `manual_run`. Gating it
would have silently removed the ability to run the cleanup by hand,
which is how it works today. The cron string is what is opt-in, and
`init()` unschedules when it is unset.

Add the new flag to the init script's scheduler condition, so enabling
only this schedule still starts `rqscheduler`.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-27 13:53:30 -07:00
Ryan McClelland
32f9ac1b90 fix(resources): handle write failures when the disk is full
The streamed resource downloads wrapped their writes in `except
httpx.TransportError`, which does not cover the `OSError` raised by
`f.write()` when the filesystem is out of space. The error escaped the
handler and the partially written file stayed on disk.

A truncated file is worse than a missing one: it satisfies the
`cover_exists` / `screenshots_exist` checks and the `file_exists` guards
in `store_ra_badge` and `store_media_file`, so later scans skip it and
never refetch it. The artwork stays permanently corrupt.

Catch `OSError` on every resource write path (covers, screenshots,
manuals, RA badges, media files and uploaded artwork) and remove the
partial file so the next scan refetches it. A stream that drops
mid-transfer leaves the same truncated file, so the transport-error
branches now discard it too. The cleanup helper swallows its own
`OSError` so it can never mask the original failure.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-27 13:34:41 -07:00
Georges-Antoine Assi
8b965c878b Merge pull request #3967 from rommapp/fix/romm-auth-secret-key-autogen
Fix ROMM_AUTH_SECRET_KEY auto-generation under nounset
2026-07-27 08:30:05 -04:00
Georges-Antoine Assi
8c21bd9d52 cleanup 2026-07-27 08:25:11 -04:00
Georges-Antoine Assi
f1b49fa9c2 cleanup 2026-07-27 08:22:25 -04:00
Georges-Antoine Assi
a93799720e Skip missing packages and reuse real title ids in the FPKGi feed
Files marked missing_from_fs were still advertised, so FPKGi listed a
package whose download URL no longer resolves.

Title ids now come from a CUSA/PPSA id in the rom or package file names
when present, falling back to the generated RomM id. It is resolved once
per rom so a base game and its updates/DLC stay grouped.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-27 08:20:49 -04:00
Georges-Antoine Assi
98651ecbf8 Fix ROMM_AUTH_SECRET_KEY auto-generation under nounset
The init script runs with `set -o nounset`, so testing `${ROMM_AUTH_SECRET_KEY}`
aborted with "unbound variable" before reaching the generation branch, leaving
the container in a restart loop. This only triggered when the variable was
omitted entirely; shipping it with an empty value took the working path.

Use `${ROMM_AUTH_SECRET_KEY-}` so the unset case is testable, and warn instead
of info since a generated key changes on every restart.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-27 08:07:50 -04:00
Georges-Antoine Assi
f896c2cc8c List each PKG file as its own FPKGi entry
FPKGi installs one package per entry, but the feed served a single entry
per rom pointing at the rom download URL, which zips multi-file roms.

Each .pkg file now gets its own entry with its own size and download URL,
named after its category (or file name) when a rom holds several packages.
Adds an optional content_type filter so FPKGi's per-category content URLs
can each point at RomM.

Fixes #3962

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-27 07:58:52 -04:00
Georges-Antoine Assi
ce49cd0c55 Merge pull request #3961 from rommapp/fix/virtual-collection-type-selector
Always allow changing the virtual collection type in v2 settings
2026-07-26 22:16:19 -04:00
Georges-Antoine Assi
3b9ac86c83 Always allow changing the virtual collection type
The selector was gated on `showVirtualCollections`, a home-page toggle
that defaults to off, so the control was disabled out of the box. The
grouping type is not home-only: the collections index and the collection
gallery read it and fetch virtual collections regardless of that toggle.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-26 18:43:11 -04:00
Georges-Antoine Assi
8fd2e7d4d0 Merge pull request #3960 from rommapp/fix/rom-child-route-visibility
Enforce hidden-rom visibility on rom child routes
2026-07-26 17:02:20 -04:00
Georges-Antoine Assi
78c8550883 cleanup 2026-07-26 16:47:00 -04:00
Georges-Antoine Assi
9b0f281df1 Bind note update/delete to the rom in the path
update_rom_note and delete_rom_note selected on note_id and user_id only,
so the rom resolved from the path never constrained which note was
touched. Pairing a note id with any other rom id in the path reached that
note regardless.

Both handlers now filter on rom_id as well, and the endpoints pass the
rom they resolved.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-26 16:42:58 -04:00
Georges-Antoine Assi
b1ac647322 Enforce hidden-rom visibility on rom child routes
The screenshot, soundtrack, manual and note routes looked up the rom by
path id but never ran the visibility gate that the core rom routes and
roms/files.py already apply, so a hidden rom stayed reachable through its
child resources.

Add assert_rom_visible() after each lookup. update_rom_note and
delete_rom_note took {id} in the path without resolving it at all, so
they now load the rom first.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-26 16:33:38 -04:00