fix: clamp page overflow to last page in /refractor status (#141) #142
@ -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"],
|
||||
|
||||
Loading…
Reference in New Issue
Block a user