perf: parallelize per-pack card fetches after roll_for_cards #99

Open
opened 2026-03-20 12:36:07 +00:00 by cal · 0 comments
Owner

Problem

In open_st_pr_packs() (helpers/main.py ~line 1772-1776), after cards are created, they're fetched back one pack at a time:

for p_id in pack_ids:
    new_cards = await db_get("cards", params=[("pack_id", p_id)])

For 5 packs = 5 sequential DB round-trips.

Proposed Fix

Use asyncio.gather() to fetch all packs' cards simultaneously. Alternatively, investigate whether db_post("cards") already returns the created cards, which would eliminate these fetches entirely.

Impact

Moderate — 5 sequential calls reduced to 1 parallel batch.

## Problem In `open_st_pr_packs()` (`helpers/main.py` ~line 1772-1776), after cards are created, they're fetched back one pack at a time: ```python for p_id in pack_ids: new_cards = await db_get("cards", params=[("pack_id", p_id)]) ``` For 5 packs = **5 sequential DB round-trips**. ## Proposed Fix Use `asyncio.gather()` to fetch all packs' cards simultaneously. Alternatively, investigate whether `db_post("cards")` already returns the created cards, which would eliminate these fetches entirely. ## Impact Moderate — 5 sequential calls reduced to 1 parallel batch.
cal added the
ai-working
performance
labels 2026-03-20 12:36:24 +00:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: cal/paper-dynasty-discord#99
No description provided.