perf: parallelize independent API calls (team lookups, injury cmds, trade validation) #90

Closed
opened 2026-03-20 13:17:16 +00:00 by cal · 1 comment
Owner

Problem

Many commands make 2–4 independent API calls sequentially when they could use asyncio.gather().

Team lookups (away + home)

  • commands/gameplay/scorebug.py lines 77–81, 184–187
  • commands/league/submit_scorecard.py lines 110–115
  • tasks/live_scorebug_tracker.py lines 120–126 (inside a per-scorecard loop — compounds)

Pattern:

away_team = await team_service.get_team(away_team_id)
home_team = await team_service.get_team(home_team_id)

Injury commands

  • commands/injuries/management.py:
    • injury_roll lines 117–125: get_current_state() + search_players() independent
    • injury_set_new lines 533–548: multiple independent service calls
    • injury_clear lines 720–741: same pattern

Trade validation

  • services/trade_builder.py lines 526–536: per-participant roster validation is sequential but independent per team

Fix

Replace sequential awaits with asyncio.gather() in each case. Example:

away_team, home_team = await asyncio.gather(
    team_service.get_team(away_team_id),
    team_service.get_team(home_team_id),
)

Impact

MEDIUM — Each location saves 50–200ms. Scorebug tracker compounds across 5+ games per update cycle.

## Problem Many commands make 2–4 independent API calls sequentially when they could use `asyncio.gather()`. ### Team lookups (away + home) - `commands/gameplay/scorebug.py` lines 77–81, 184–187 - `commands/league/submit_scorecard.py` lines 110–115 - `tasks/live_scorebug_tracker.py` lines 120–126 (inside a per-scorecard loop — compounds) Pattern: ```python away_team = await team_service.get_team(away_team_id) home_team = await team_service.get_team(home_team_id) ``` ### Injury commands - `commands/injuries/management.py`: - `injury_roll` lines 117–125: `get_current_state()` + `search_players()` independent - `injury_set_new` lines 533–548: multiple independent service calls - `injury_clear` lines 720–741: same pattern ### Trade validation - `services/trade_builder.py` lines 526–536: per-participant roster validation is sequential but independent per team ## Fix Replace sequential awaits with `asyncio.gather()` in each case. Example: ```python away_team, home_team = await asyncio.gather( team_service.get_team(away_team_id), team_service.get_team(home_team_id), ) ``` ## Impact **MEDIUM** — Each location saves 50–200ms. Scorebug tracker compounds across 5+ games per update cycle.
cal added the
ai-working
label 2026-03-20 13:18:36 +00:00
cal removed the
ai-working
label 2026-03-20 13:21:32 +00:00
Claude added the
ai-working
label 2026-03-20 16:01:11 +00:00
Claude added the
status/in-progress
label 2026-03-20 16:04:40 +00:00
Claude added the
status/pr-open
label 2026-03-20 16:08:41 +00:00
Collaborator

PR #106 opened: #106

Replaced all sequential awaits with asyncio.gather() across 5 files:

  • scorebug.py: Both commands now fetch away/home teams in parallel (uses asyncio.sleep(0) as a None-returning coroutine for optional IDs)
  • submit_scorecard.py: Parallel team-by-abbreviation lookups
  • live_scorebug_tracker.py: Parallel team lookups inside the 3-minute update loop
  • injuries/management.py: Parallel get_current_state() + search_players() in all 3 injury commands
  • trade_builder.py: All participant roster validations gathered in parallel

Also fixed missing await on scorecard_tracker async methods in scorebug.py and live_scorebug_tracker.py (auto-corrected by linter — those methods were made async in a prior working-tree change).

PR #106 opened: https://git.manticorum.com/cal/major-domo-v2/pulls/106 Replaced all sequential awaits with `asyncio.gather()` across 5 files: - **scorebug.py**: Both commands now fetch away/home teams in parallel (uses `asyncio.sleep(0)` as a None-returning coroutine for optional IDs) - **submit_scorecard.py**: Parallel team-by-abbreviation lookups - **live_scorebug_tracker.py**: Parallel team lookups inside the 3-minute update loop - **injuries/management.py**: Parallel `get_current_state()` + `search_players()` in all 3 injury commands - **trade_builder.py**: All participant roster validations gathered in parallel Also fixed missing `await` on `scorecard_tracker` async methods in `scorebug.py` and `live_scorebug_tracker.py` (auto-corrected by linter — those methods were made async in a prior working-tree change).
Claude added
ai-pr-opened
and removed
ai-working
labels 2026-03-20 16:08:53 +00:00
cal closed this issue 2026-03-20 17:48:29 +00:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 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/major-domo-v2#90
No description provided.