perf: N+1 sequential player/creator lookups in loops #89
Labels
No Label
ai-changes-requested
ai-pr-opened
ai-reviewed
ai-reviewing
ai-working
in-next-release
status/in-progress
status/pr-open
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/major-domo-v2#89
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
Multiple service methods loop over a list and make one API call per item sequentially.
services/decision_service.pylines 127–143 (find_winning_losing_pitchers)5–10 sequential calls per game that are all independent.
services/custom_commands_service.pylines 463–707Three methods (
get_popular_commands,get_commands_needing_warning,get_commands_eligible_for_deletion) each fetch a list then loop callingget_creator_by_id()per item:Fix
Gather all lookups in parallel:
For custom_commands, either gather creator lookups or use the API's embedded-creator response format (already used in
get_commands_by_creator).Impact
HIGH (decision_service — game processing path), MEDIUM (custom_commands — admin)
Opened PR #118: #118
Fix approach:
decision_service.find_winning_losing_pitchers: all IDs (wp, lp, sv, holds, blown saves) are placed in a single ordered list and fetched in oneasyncio.gather().asyncio.sleep(0, result=None)serves as a no-op for None IDs, preserving theNonesentinel without a branch on the gather list.custom_commands_service(3 methods):get_creator_by_id()calls gathered withreturn_exceptions=True. Post-gather loop preserves original behavior:BotException→ log+skip; other exceptions → re-raise.977 passed, 2 skipped.