perf: parallelize get_card_embeds calls in display_cards (#98) #157
No reviewers
Labels
No Label
ai-changes-requested
ai-failed
ai-pr-opened
ai-reviewed
ai-reviewing
ai-working
ai-working
bug
enhancement
feature
in-queue
performance
security
tech-debt
todo
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/paper-dynasty-discord#157
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "issue/98-perf-parallelize-get-card-embeds-calls-in-display"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #98
Summary
Replace sequential
await-in-list-comprehension withasyncio.gather()indisplay_cards():Impact
Each
get_card_embeds()makes 2 DB round-trips (refractor state + paperdex lookup). For a standard 5-pack open (25 cards), this eliminates 50 sequential round-trips and replaces them with ~2 concurrent batches.asynciowas already imported.list()wraps the result sinceasyncio.gather()returns a tuple; downstream code indexescard_embedslike a list.Files Changed
helpers/main.py— 1-line change at line 342AI Code Review
Files Reviewed
helpers/main.py(modified — line 342)Findings
Correctness
No issues found. The change is a correct, idiomatic asyncio parallelization:
asynciois already imported at line 1.asyncio.gather()accepts an unpacked list of coroutines — correct usage.cardsinput:asyncio.gather()with no arguments returns[], safe.get_card_embeds()call still bubbles up throughgatherand is caught by the existingexcept Exception as eblock at line 350, returningFalse.One minor inaccuracy in the PR body:
asyncio.gather()when awaited returns alist, not a tuple. Thelist()wrapper is therefore a no-op (a shallow copy), not a type conversion. This is harmless but the PR body comment could mislead future contributors.Security
No issues found. No user input flows through the changed line.
Style & Conventions
No issues found. Parallelizing async calls with
asyncio.gather()is the established pattern in this codebase.Suggestions
list()wrapper is unnecessary sinceawait asyncio.gather(...)already returns alist. It can stay, but consider correcting the PR body comment to avoid the "returns a tuple" misconception.Verdict: APPROVED
Clean 1-line change. Correctly converts a sequential await-in-comprehension to a parallel
asyncio.gather(). Error handling, empty-input, and downstream list indexing are all unaffected. Gitea blocks self-approval — posting as COMMENT.Automated review by Claude PR Reviewer
Approved via pd-pr