This commit is contained in:
Georges-Antoine Assi
2026-05-24 18:57:38 -04:00
parent fb13f54f48
commit 1a560d3660
3 changed files with 12 additions and 9 deletions

View File

@@ -528,6 +528,7 @@ def get_roms(
player_counts_logic=player_counts_logic,
group_by_meta_id=group_by_meta_id,
updated_after=updated_after,
include_file_stats=True,
)
# Get the char index for the roms

View File

@@ -549,6 +549,7 @@ class DBRomsHandler(DBBaseHandler):
player_counts_logic: str = "any",
user_id: int | None = None,
updated_after: datetime | None = None,
include_file_stats: bool = False,
session: Session = None, # type: ignore
) -> Query[Rom]:
from handler.scan_handler import MetadataSource
@@ -566,11 +567,16 @@ class DBRomsHandler(DBBaseHandler):
),
# Show notes indicator on cards
selectinload(Rom.notes),
# Gallery card needs file types and counts
undefer(Rom.multi_file),
undefer(Rom.top_level_file_count),
)
# Correlated subqueries and only undefer when the caller serializes the
# gallery-card flags. Feeds and filter-value lookups don't need them.
if include_file_stats:
query = query.options(
undefer(Rom.multi_file),
undefer(Rom.top_level_file_count),
)
# Handle platform filtering - platform filtering always uses OR logic since ROMs belong to only one platform
if platform_ids:
query = self._filter_by_platform_ids(query, platform_ids)

View File

@@ -446,12 +446,8 @@ class Rom(BaseModel):
return f"{self.fs_name} ({self.id})"
# Gallery-card flags derived from rom_files, computed by the database as
# correlated subqueries so the list endpoint never has to load the rom_files
# rows themselves. Deferred so single-row queries that don't read the flags
# (scan, file CRUD, etc.) don't pay for the subqueries; the gallery list and
# detail endpoints opt in via `undefer`. Defined out-of-line because they
# reference both Rom and RomFile.
# Correlated scalar subqueries against rom_files, deferred and opt-in via `undefer`
# Revisit (real columns, JOIN/aggregate, or added indexes) if gallery latency regresses
_rom_full_path = func.concat(Rom.fs_path, "/", Rom.fs_name)
Rom.multi_file = column_property(