perf(roms): make full rom id index opt-out on GET /api/roms#3781
Merged
Conversation
The home rails ("recently added" / "continue playing") request 15 cards
but the endpoint always computed rom_id_index, the complete ordered list
of every matching rom id that backs gallery virtual scroll. On large
libraries this ran a full-table scan and shipped hundreds of KB of ids
to render 15 cards.
Add a with_rom_id_index query param (defaults to true, mirroring the
existing with_char_index / with_filter_values flags). When false, skip
building the index and serve the page directly via offset/limit off the
sort index, with a lightweight count for total. The home rail fetches
pass false.
Fixes #3770
Generated-By: PostHog Code
Task-Id: 45dbad45-bd7c-4cf3-8e8f-105f174f4386
Contributor
Greptile SummaryThis PR lets small ROM requests skip the full ROM ID index. The main changes are:
Confidence Score: 5/5This looks safe to merge.
Important Files Changed
Reviews (1): Last reviewed commit: "perf(roms): make full rom id index opt-o..." | Re-trigger Greptile |
greptile-apps
Bot
dismissed
their stale review
July 17, 2026 01:01
Dismissed because a newer commit was pushed; Greptile will re-review the current head.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Explain the changes or enhancements you are proposing with this pull request.
Fixes #3770
The home page rails ("recently added" and "continue playing") call
GET /api/roms?limit=15&order_by=id&order_dir=desc. That endpoint always computesrom_id_index, the complete ordered list of every matching rom id, which exists to back the gallery's virtual scroll. On a large library (the reporter has ~92,800 roms) this means:SELECT id FROM roms ORDER BY id DESC) that took ~5.3s uncached, andThere were already opt-outs for the other sidecars (
with_char_index,with_filter_values) but none forrom_id_index.Changes
with_rom_id_indexquery param toGET /api/roms, defaulting totruefor backwards compatibility (mirroring the existing sidecar flags). Whenfalse, the full index is skipped and the requested page is served directly withoffset/limitoff the sort index, with a lightweightCOUNT(*)fortotal. Added aget_rom_count()handler helper for the count. Default behavior (virtual-scroll gallery) is unchanged.getRecentRoms/getRecentPlayedRoms, plus their cache-clear mirrors) now passwith_rom_id_index: false.A 15-card rail now costs a small page query plus a count, and a few KB of payload.
The response schema is unchanged (
rom_id_indexis still present, just empty when opted out), so no OpenAPI/type regeneration is needed.AI assistance disclosure
This change was written with AI assistance (PostHog Code / Claude). The implementation, tests, and verification were AI-generated and human-reviewed.
Checklist
Please check all that apply.
Screenshots (if applicable)
N/A (backend/data-fetching change, no visual difference).
Created with PostHog Code