fix: use server-side pagination and fix limit=500 exceeding API max
- Switch from client-side pagination (fetch all, slice) to server-side (pass limit/offset/progress params to API) - Fixes limit=500 rejection (API max is 100) - Footer now shows total_count from API response - progress=close filter delegated to API instead of client-side Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
c285e9e12d
commit
a9ef04d102
@ -167,13 +167,17 @@ class Refractor(commands.Cog):
|
||||
)
|
||||
return
|
||||
|
||||
params = [("team_id", team["id"]), ("limit", 500)]
|
||||
page = max(1, page)
|
||||
offset = (page - 1) * PAGE_SIZE
|
||||
params = [("team_id", team["id"]), ("limit", PAGE_SIZE), ("offset", offset)]
|
||||
if card_type:
|
||||
params.append(("card_type", card_type))
|
||||
if season is not None:
|
||||
params.append(("season", season))
|
||||
if tier is not None:
|
||||
params.append(("tier", tier))
|
||||
if progress:
|
||||
params.append(("progress", progress))
|
||||
|
||||
data = await db_get("refractor/cards", params=params)
|
||||
if not data:
|
||||
@ -183,21 +187,23 @@ class Refractor(commands.Cog):
|
||||
return
|
||||
|
||||
items = data if isinstance(data, list) else data.get("items", [])
|
||||
total_count = (
|
||||
data.get("count", len(items)) if isinstance(data, dict) else len(items)
|
||||
)
|
||||
if not items:
|
||||
await interaction.edit_original_response(
|
||||
content="No refractor data found for your team."
|
||||
)
|
||||
return
|
||||
|
||||
if progress == "close":
|
||||
items = apply_close_filter(items)
|
||||
if not items:
|
||||
if progress == "close":
|
||||
await interaction.edit_original_response(
|
||||
content="No cards are currently close to a tier advancement."
|
||||
)
|
||||
return
|
||||
else:
|
||||
await interaction.edit_original_response(
|
||||
content="No refractor data found for your team."
|
||||
)
|
||||
return
|
||||
|
||||
page_items, total_pages = paginate(items, page)
|
||||
total_pages = max(1, (total_count + PAGE_SIZE - 1) // PAGE_SIZE)
|
||||
page = min(page, total_pages)
|
||||
page_items = items
|
||||
lines = [format_refractor_entry(state) for state in page_items]
|
||||
|
||||
embed = discord.Embed(
|
||||
@ -205,7 +211,9 @@ class Refractor(commands.Cog):
|
||||
description="\n\n".join(lines),
|
||||
color=0x6F42C1,
|
||||
)
|
||||
embed.set_footer(text=f"Page {page}/{total_pages} · {len(items)} card(s) total")
|
||||
embed.set_footer(
|
||||
text=f"Page {page}/{total_pages} · {total_count} card(s) total"
|
||||
)
|
||||
|
||||
await interaction.edit_original_response(embed=embed)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user