Skip to content

Add missing index on rom_files(rom_id) to fix slow game listing on large ROM sets#3259

Merged
gantoine merged 2 commits intomasterfrom
copilot/add-indices-to-roms-rom-files
Apr 14, 2026
Merged

Add missing index on rom_files(rom_id) to fix slow game listing on large ROM sets#3259
gantoine merged 2 commits intomasterfrom
copilot/add-indices-to-roms-rom-files

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 14, 2026

On large libraries (60k+ ROMs), listing games per platform was taking 4500ms+ due to a sequential scan on rom_files when joining to roms. The FK column rom_files.rom_id had no index — only the PK id was indexed.

Note: roms(platform_id) is already covered by the existing composite index idx_roms_platform_id_fs_name (leftmost-prefix).

Changes

  • models/rom.py — Added __table_args__ to RomFile with idx_rom_files_rom_id index on rom_id
  • alembic/versions/0079_add_rom_files_rom_id_index.py — Migration to create the index on existing databases
class RomFile(BaseModel):
    __tablename__ = "rom_files"

    __table_args__ = (Index("idx_rom_files_rom_id", "rom_id"),)

Copilot AI changed the title [WIP] Add indices on roms and rom_files for improved performance Add missing index on rom_files(rom_id) to fix slow game listing on large ROM sets Apr 14, 2026
Copilot AI requested a review from gantoine April 14, 2026 02:36
@gantoine gantoine marked this pull request as ready for review April 14, 2026 13:02
Copilot AI review requested due to automatic review settings April 14, 2026 13:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an explicit DB index on rom_files.rom_id to eliminate slow sequential scans when joining rom_files to roms for large libraries, improving game listing performance.

Changes:

  • Add SQLAlchemy model-level index idx_rom_files_rom_id on RomFile.rom_id.
  • Add Alembic migration to create/drop the same index on existing databases.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
backend/models/rom.py Defines idx_rom_files_rom_id on rom_files(rom_id) at the ORM/schema level.
backend/alembic/versions/0079_add_rom_files_rom_id_index.py Creates the rom_files(rom_id) index for existing installations (with downgrade).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link
Copy Markdown
Contributor

Test Results (mariadb)

1 243 tests   1 243 ✅  3m 50s ⏱️
    1 suites      0 💤
    1 files        0 ❌

Results for commit ce5624b.

@github-actions
Copy link
Copy Markdown
Contributor

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
16038 10896 68% 0% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
backend/models/rom.py 91% 🟢
TOTAL 91% 🟢

updated for commit: ce5624b by action🐍

@github-actions
Copy link
Copy Markdown
Contributor

Test Results (postgresql)

1 243 tests   1 243 ✅  3m 52s ⏱️
    1 suites      0 💤
    1 files        0 ❌

Results for commit ce5624b.

@gantoine gantoine merged commit 7724aab into master Apr 14, 2026
18 checks passed
@gantoine gantoine deleted the copilot/add-indices-to-roms-rom-files branch April 14, 2026 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] PostgreSQL performance listing games is slow due to missing indices when large romset

3 participants