perf: replace blocking requests.get with aiohttp in get_player_headshot #100
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
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/paper-dynasty-discord#100
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
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?
Problem
get_player_headshot()inhelpers/main.py(~line 73) uses synchronousrequests.get()to scrape headshot images from baseball-reference.com. This blocks the entire bot event loop for up to 2 seconds per card that's missing a cached headshot.While this only triggers on cache miss (first display of a new player), when opening packs with new players it can add significant delay and freeze all other bot operations.
Proposed Fix
Replace
requests.get(req_url, timeout=2)withaiohttp.ClientSession(already used elsewhere in the codebase viaapi_calls.py). Run in an async context so the event loop isn't blocked.Impact
Prevents event loop stalls on headshot cache misses. Critical for new cardset releases where many players won't have cached headshots yet.