fix: clamp page overflow to last page in /refractor status (#141)
All checks were successful
Ruff Lint / lint (pull_request) Successful in 30s
All checks were successful
Ruff Lint / lint (pull_request) Successful in 30s
When page exceeds total pages, API returns empty items but non-zero count. Now detects this case and re-fetches the last valid page. Closes #141 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
5cfddaa89a
commit
cb17b99220
@ -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