fix: clamp page overflow to last page in /refractor status (#141) #142

Merged
cal merged 1 commits from issue/141-bug-refractor-status-page-overflow-shows-no-data-i into main 2026-04-07 15:52:07 +00:00

View File

@ -370,6 +370,18 @@ class Refractor(commands.Cog):
total_count = (
data.get("count", len(items)) if isinstance(data, dict) else len(items)
)
# If the requested page is beyond the last page, clamp and re-fetch.
if not items and total_count > 0:
total_pages = max(1, (total_count + PAGE_SIZE - 1) // PAGE_SIZE)
page = total_pages
clamped_params = [(k, v) for k, v in params if k != "offset"]
clamped_params.append(("offset", (page - 1) * PAGE_SIZE))
data = await db_get("refractor/cards", params=clamped_params)
if isinstance(data, dict):
items = data.get("items", [])
total_count = data.get("count", total_count)
logger.debug(
"Refractor status for team %s: %d items returned, %d total (page %d)",
team["id"],