mirror of
https://github.com/rommapp/romm.git
synced 2026-11-29 10:01:00 +01:00
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>