mirror of
https://github.com/rommapp/romm.git
synced 2026-11-30 18:42:34 +01:00
Merge pull request #3259 from rommapp/copilot/add-indices-to-roms-rom-files
Add missing index on `rom_files(rom_id)` to fix slow game listing on large ROM sets
This commit is contained in:
30
backend/alembic/versions/0079_add_rom_files_rom_id_index.py
Normal file
30
backend/alembic/versions/0079_add_rom_files_rom_id_index.py
Normal file
@@ -0,0 +1,30 @@
|
||||
"""Add index on rom_id for rom_files table
|
||||
|
||||
Revision ID: 0079_add_rom_files_rom_id_index
|
||||
Revises: 0078_add_libretro_id_to_roms
|
||||
Create Date: 2026-04-14 00:00:00.000000
|
||||
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "0079_add_rom_files_rom_id_index"
|
||||
down_revision = "0078_add_libretro_id_to_roms"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
with op.batch_alter_table("rom_files", schema=None) as batch_op:
|
||||
batch_op.create_index(
|
||||
"idx_rom_files_rom_id",
|
||||
["rom_id"],
|
||||
unique=False,
|
||||
if_not_exists=True,
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
with op.batch_alter_table("rom_files", schema=None) as batch_op:
|
||||
batch_op.drop_index("idx_rom_files_rom_id", if_exists=True)
|
||||
@@ -64,6 +64,8 @@ class SiblingRom(BaseModel):
|
||||
class RomFile(BaseModel):
|
||||
__tablename__ = "rom_files"
|
||||
|
||||
__table_args__ = (Index("idx_rom_files_rom_id", "rom_id"),)
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
rom_id: Mapped[int] = mapped_column(ForeignKey("roms.id", ondelete="CASCADE"))
|
||||
file_name: Mapped[str] = mapped_column(String(length=FILE_NAME_MAX_LENGTH))
|
||||
|
||||
Reference in New Issue
Block a user