The Server Stats page ran two full scans of the multi-gigabyte `roms`
table on every visit: the metadata-coverage breakdown counted eleven
provider-id columns per platform, and the region breakdown pulled every
row's regions into Python. Both were returned in the same request as the
cheap summary counts, so the whole page stayed blank until they finished.
Mirror the provider match ids into the narrow `roms_facets` table
(migration 0102, kept in sync by the same triggers as the existing facet
columns) and read both breakdowns from it, so neither query touches
`roms`. Split the v2 Server Stats view into a summary-first request and a
separate breakdown request so the six top cards render immediately.
Fixes#3901
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
remove_persisted_cover swallowed OSError, so clearing cover_path
regardless dropped the only reference to a file still on disk. It now
reports whether the file is gone, and the path is kept for the next scan
to retry when it isn't.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The two halves always ran together, and the column copy they shared is
now a single helper.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
A scanned row leaves unset columns as None and the model defaults only
apply on insert, so the reconciliation path could write NULL into
file_size_bytes or has_embedded_cover. Unset values now leave the stored
value alone.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
A file that stopped carrying audio tags, or vanished from disk, had its
track_meta row dropped (directly or by cascade), leaving its persisted
cover on disk with nothing pointing at it.
sync_rom_files now reports those cover paths so the scan unlinks them,
keeping filesystem work out of the database handler.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Reusing the file row across rescans meant a track that kept its tags but
lost its embedded cover held on to the old cover_path, so the music API
kept serving an obsolete image and its file was never removed.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Rescans deleted and re-inserted every rom_files row, so file ids churned
on each scan and anything keyed on them (track metadata, persisted
soundtrack covers) was orphaned.
Rows are now matched by path first, then by content hash so a file
renamed or moved inside the ROM keeps its id, mirroring the ROM-level
reassociation. Only changed columns are written, vanished files are
deleted, and archive_members is carried over (the hand-written copy
dropped it).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The per-platform breakdown rendered the raw allPlatforms list, so empty
(0-game) platforms left in the DB leaked through. The Platforms page, Home
screen, and this page's own summary counter all exclude them, so the list
disagreed with everything else.
Switch to the shared filledPlatforms getter (rom_count > 0) so the list is
consistent by construction with the rest of the app.
Fixes#3897
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
A member that failed or timed out mid-archive ended the member stream
silently, so the caller kept the composite hash built from the members
that happened to succeed. Raise ArchiveReadError instead and fall back to
hashing the archive's raw bytes, with no archive_members recorded.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
_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>
Migrations run at startup before the app serves traffic, so no write can
race the backfill. Populating the empty table first means no row can
conflict, dropping the per-engine upsert guards and collapsing the two
backfill statements into one.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
RomM's nginx served everything under /assets, plus the root favicons and
manifest, with no Cache-Control, so browsers re-fetched or revalidated the
frontend bundle and every cover image on repeat visits.
Only some of these assets are safe to cache long-term, so a blanket immutable
rule is unsafe. Cache by fingerprint instead:
- Content-hashed bundles (index-<hash>.js) and library resources that carry a
cache-busting query (covers ?ts=, manuals ?v=) -> public, max-age=31536000,
immutable.
- Query-less library resources (screenshots and RA badges, which reuse stable
filenames and are overwritten on re-scrape), the bundled EmulatorJS/Ruffle
runtimes, and other static files under /assets -> public, max-age=3600,
must-revalidate.
- index.html and the root favicons/manifest/service worker -> no-cache, so a
new deploy's bundles and any updated runtime are picked up at once.
The resources split is driven by an $is_args map, so a resource is frozen only
while its URL carries a busting query.
Fixes#3890
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
A ROM written between the backfill and the trigger creation was captured by
neither, leaving its facet row missing or stale until the next write. The
triggers now go in first and the backfill skips rows they already wrote,
since those were built from the write itself.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The bundled 7zz is built without the RAR codec (unRAR license), so it can
neither list nor extract RAR members. Every content-based match silently
came up empty for .rar: no RetroAchievements hash and no CRC/MD5/SHA-1 for
hash-database providers.
RAR listing and extraction now go through libarchive's bsdtar, added to the
images as libarchive-tools. Listing uses an mtree rewrite (libarchive's only
machine-readable listing) and member names are escaped before being handed
back to bsdtar, which matches them as globs.
Fixes#3884
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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>
Building the filter dropdowns aggregated the facet columns straight off
`roms`. Those columns are cheap to compute since #3826, but they sit inline
with the raw provider-metadata blobs, so the aggregation read every row of a
multi-gigabyte table: seconds of pure disk reading on any database whose
buffer pool is smaller than the table (the stock 128-256 MB defaults always
are on a large library).
`roms_facets` holds only the filter values and is kept in sync by AFTER
INSERT/UPDATE triggers on `roms`, so every write path stays consistent
without an application hook. Deletes ride the ON DELETE CASCADE foreign key.
Fixes#3882
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Replaces the DOM-level keyboard-owner heuristic: instead of sniffing for
canvases, emulator containers and fullscreen elements, take the running
state from EJS_onGameStart. One source of truth (the playing store), no
false positives on the 3D box art canvas, videos or fullscreen UI.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The 8+6 digit regex still admits values like 20201301T000000, and feeding
one to TIMESTAMPDIFF raises "Incorrect datetime value" under the default
STRICT_TRANS_TABLES, aborting the migration on an existing row or a later
insert. CAST(... AS DATETIME), which would yield NULL, is itself barred
from a generated column, so the components are range-checked (including
leap years) in the CASE guard and invalid dates fall through to NULL.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Adds a `win9x` universal platform slug, mapped to ScreenScraper system
137 (PC Win9X), so Windows 9x libraries can be scanned and matched.
The ES-DE config example gains the `windows9x` folder mapping, plus the
`windows3x` mapping that was missing.
Closes#3875
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
MariaDB 12.3 enforces that STR_TO_DATE (which reads lc_time_names) cannot
appear in a GENERATED ALWAYS AS clause, so migration 0098 failed with
error 1901 and RomM could not start. Earlier releases up to 12.2 accepted
it, which is why the problem only surfaced on 12.3.
The gamelist value is already pinned to a fixed-width "YYYYMMDDThhmmss" by
the regex guard, so it is reshaped into a canonical datetime literal with
SUBSTRING/CONCAT and fed to the existing TIMESTAMPDIFF. Stored values and
their time-zone independence are unchanged.
Fixes#3873
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Typing "/" at a DOSBox prompt (e.g. "mount A / -t floppy") navigated to
the search page. Emulator canvases take keystrokes off window/document
rather than through a focused form control, so the keypress looked like
a plain "/" on <body> to the global hotkey handler.
The playing store flag already gates the handler, but it depends on each
player view keeping it current. Add a DOM-level guard that holds even
when the flag is stale: ignore keys whose target or activeElement sits
inside an emulator container (EmulatorJS, Ruffle), a canvas or a video,
and ignore everything while an element is fullscreen.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Adds a reusable skill that encodes a two-speed workflow (fast direct
sweeps plus fanned-out parallel deep review) for auditing a release tag
range or PR diff for malicious changes or security regressions: supply
chain, egress/exfiltration, auth/injection/traversal, CI/infra, and
commit provenance. Registered in the CLAUDE.md skills table.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Leaving EmulatorJS triggers a full page reload (to reset COOP/COEP) that
aborts the in-flight play-session POST. Add an ingestPlaySessionsKeepalive
variant using fetch with keepalive (plus the session cookie and CSRF header),
and have usePlaySession.flush() use it so the session is recorded even as the
document unloads.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Wire usePlaySession into the v2 EmulatorJS view so a session is recorded on
any exit path (in-emulator Exit/Save & Quit, back nav, or route change),
starting when the game goes live and flushing on unmount. flush() is
idempotent so overlapping exit paths can't double-submit.
Remove the play-session ingest from the shared v1 Player component so there
is a single source of truth and no double-recording. immediateExit now only
navigates back to the game details view.
Note: Player.vue is also mounted by the v1 EmulatorJS view, which no longer
records sessions as a result; acceptable while v1 is frozen and slated for
removal.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Move the per-play status update (last_played, now_playing, and the
finished/empty -> incomplete rewind) off the optimistic launch-time write
and onto play-session ingest, so it reflects real play and is recorded once.
Backend: ingest now updates rom_user status when a session is the newest
play, leaving deliberate statuses (completed_100 / retired / never_playing)
untouched and skipping backfilled older sessions so they can't resurrect
now_playing.
Frontend: new usePlaySession composable records a session and ingests it on
exit; wired into Ruffle and Stream. EmulatorJS already ingests via the
embedded v1 Player, so its launch-time recordLaunch is dropped. The dead
recordLaunch / applyLaunchStatus helpers are removed.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The Collections tab renders every collection tile's artwork through
CollectionMosaic, but its <img> tags lacked loading="lazy"/decoding="async".
With hundreds of virtual collections the browser eagerly fetched every cover,
flooding the server with image requests for off-screen tiles.
Add the same lazy hints GameCover already uses to both image branches so
artwork is only fetched near the viewport. CollectionListRow reuses this
component, so grid and list layouts both benefit.
Fixes#3865
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The collection Settings tab re-snapshotted the form from `props.collection`
right after a successful PUT, but that prop only receives the fresh value
on the next microtask (store array-replace + parent ref reassign). So the
snapshot read the pre-save object and reverted `form.isPublic` to its old
value, leaving `dirty` true and the Apply button visible even though the
change was persisted.
Snapshot from the update response instead: `snapshot()` now accepts an
optional source collection, and `save()` passes the returned `data`.
Fixes#3864
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Move recordLaunch out of the claimSession try/catch and run it after a
successful claim (gated on playerState === "playing"). The launch-status
write is incidental metadata, so keeping it inside the launch transaction
risked coupling it to the claimed-session lifecycle; running it afterward
ensures it can never affect play or leave a claimed session needing cleanup.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The launch write optimistically mutated the shared rom_user but was
fire-and-forget, so a network/authorization/server failure produced an
unhandled rejection while the client kept status values that were never
persisted. Introduce a shared recordLaunch() helper that snapshots the
fields, applies the optimistic update, and on failure reverts them and logs
instead of leaving the rejection unhandled. Use it in all three v2 players
(EmulatorJS, Ruffle, Stream) so the behavior is consistent.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>