Skip to content

Commit 43cdd08

Browse files
gantoineclaude
andcommitted
refactor(roms): resolve the page total in a helper
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 0be6e3a commit 43cdd08

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

backend/endpoints/roms/__init__.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -845,11 +845,20 @@ def _transform(items: Sequence[Rom]) -> list[SimpleRomSchema]:
845845
for item in items
846846
]
847847

848+
def resolve_total() -> int | None:
849+
if with_rom_id_index:
850+
# The index already spans the result set, so the count is free.
851+
return len(rom_id_index)
852+
# Without the index the count is its own scan of the filtered set,
853+
# so a caller scrolling a gallery it already sized opts out.
854+
return (
855+
db_rom_handler.get_rom_count(query=query, session=session)
856+
if with_total
857+
else None
858+
)
859+
848860
params = resolve_params()
849-
total: int | None
850861
if with_rom_id_index:
851-
# The index already spans the result set, so the count is free.
852-
total = len(rom_id_index)
853862
page_ids = list(rom_id_index[params.offset : params.offset + params.limit])
854863
if page_ids:
855864
page_rows = session.scalars(query.where(Rom.id.in_(page_ids))).all()
@@ -863,18 +872,11 @@ def _transform(items: Sequence[Rom]) -> list[SimpleRomSchema]:
863872
page_items = list(
864873
session.scalars(query.offset(params.offset).limit(params.limit)).all()
865874
)
866-
# Without the index the count is its own scan of the filtered set,
867-
# so a caller scrolling a gallery it already sized opts out.
868-
total = (
869-
db_rom_handler.get_rom_count(query=query, session=session)
870-
if with_total
871-
else None
872-
)
873875

874876
return CustomLimitOffsetPage.create(
875877
_transform(page_items),
876878
params,
877-
total=total,
879+
total=resolve_total(),
878880
char_index=char_index_dict,
879881
rom_id_index=list(rom_id_index),
880882
filter_values=filter_values,

frontend/src/services/api/rom.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ export interface GetRomsParams {
183183
playerCountsLogic?: string | null;
184184
metadataProvidersLogic?: string | null;
185185
tagsLogic?: string | null;
186-
// Skip the char index / filter-value / id-index aggregations server-side
187186
withCharIndex?: boolean;
188187
withFilterValues?: boolean;
189188
withRomIdIndex?: boolean;

0 commit comments

Comments
 (0)