Commit Graph

2 Commits

Author SHA1 Message Date
Georges-Antoine Assi
56a57da11e fix(backend): tolerate calendar-invalid gamelist dates on PostgreSQL
The gamelist branch of generated_first_release_date is gated on an
8-digits/T/6-digits regex, which does not prove the digits form a real
date. EmulationStation, ES-DE and Skyscraper write "00000000T000000" for
an unknown release date, and make_timestamp raises on it. Because the
column is STORED, that aborts the 0098 ALTER TABLE on upgrade, and any
later INSERT of such a ROM on installs already past 0098.

romm_gamelist_epoch_ms now traps the error and returns NULL, matching the
range guard the MariaDB branch already applied. 0105 replaces the
function in place for installs that have already run 0098.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-30 21:03:54 -04:00
Georges-Antoine Assi
dfac9dab2b perf(backend): make roms_metadata fast via generated columns
The roms_metadata VIEW re-derived its facet columns by JSON-parsing up to
eight raw provider-metadata blobs on every roms row, on every query, making
galleries, search, and sorts CPU-bound on large libraries.

Move the per-row derivation into STORED generated columns on roms (rm_*),
maintained automatically by the database engine (no application hook, no
background job). roms_metadata is redefined as a thin projection over them,
so the RomMetadata model, every handler query, and the virtual_collections
view are unchanged and inherit the speedup. Indexes on the release-date,
rating, and player-count columns back the corresponding sorts and filters.

On a 75k-row MariaDB library: release-date sort 1.15s -> 0.05s, facet-value
scan 3.35s -> 0.18s, player-count filter 0.54s -> 0.04s; virtual_collections
4.2s -> 1.3s. Generated columns match the old view byte-for-byte across all
rows except the quoted-string dates the old view silently truncated to 0.

Cross-engine correctness:
- MariaDB JSON_UNQUOTE before every numeric CAST avoids strict-mode INSERT
  truncation on quoted values.
- PostgreSQL to_timestamp()/jsonb_build_array() are only STABLE and illegal
  in generated columns; the gamelist date and age-ratings derivations run
  through IMMUTABLE wrapper functions. Gamelist dates are parsed as UTC on
  both engines so the stored value is time-zone independent.

Fixes #3768.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-19 09:19:34 -04:00