perf: redundant GET after create/update in custom_commands_service #95

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

Problem

Several methods in services/custom_commands_service.py make an extra GET request after a POST/PUT, even though the API response already contains the created/updated object.

Locations

  • create_command() line 123: GET after POST
  • update_command() line 220: GET after PUT
  • get_or_create_creator() line 539: GET after PUT (3 total round-trips: GET + PUT + GET)
  • help_commands_service: create_help() line 104, update_help() line 207 — same pattern

Also in services/draft_list_service.py lines 181–188

add_to_list() does GET + POST + verification GET (3 round-trips). Other mutation methods (remove_player_from_list, move_entry_up, etc.) skip the verification.

Also in services/custom_commands_service.py lines 611–648 (get_statistics)

9 sequential independent API calls for the stats dashboard. All are independent and could be gathered.

Fix

Return the API response directly from POST/PUT instead of making a second GET:

response = await client.post("custom_commands", command_data)
return CustomCommand(**response)  # Use the response directly

For get_statistics, use asyncio.gather() for all 9 calls.

Impact

LOW-MEDIUM — Custom commands aren't the highest-frequency path, but each redundant call adds 50–100ms.

## Problem Several methods in `services/custom_commands_service.py` make an extra GET request after a POST/PUT, even though the API response already contains the created/updated object. ### Locations - `create_command()` line 123: GET after POST - `update_command()` line 220: GET after PUT - `get_or_create_creator()` line 539: GET after PUT (3 total round-trips: GET + PUT + GET) - `help_commands_service`: `create_help()` line 104, `update_help()` line 207 — same pattern ### Also in `services/draft_list_service.py` lines 181–188 `add_to_list()` does GET + POST + verification GET (3 round-trips). Other mutation methods (`remove_player_from_list`, `move_entry_up`, etc.) skip the verification. ### Also in `services/custom_commands_service.py` lines 611–648 (`get_statistics`) 9 sequential independent API calls for the stats dashboard. All are independent and could be gathered. ## Fix Return the API response directly from POST/PUT instead of making a second GET: ```python response = await client.post("custom_commands", command_data) return CustomCommand(**response) # Use the response directly ``` For `get_statistics`, use `asyncio.gather()` for all 9 calls. ## Impact **LOW-MEDIUM** — Custom commands aren't the highest-frequency path, but each redundant call adds 50–100ms.
cal added the
ai-working
label 2026-03-20 13:18:40 +00:00
cal removed the
ai-working
label 2026-03-20 13:21:33 +00:00
Claude added the
ai-working
label 2026-03-20 18:01:13 +00:00
Claude added the
status/in-progress
label 2026-03-20 18:05:47 +00:00
Claude removed the
status/in-progress
label 2026-03-20 18:09:35 +00:00
Collaborator

PR #112 opened: #112

Approach: Eliminated redundant GET requests after POST/PUT in custom_commands_service and help_commands_service by returning API responses directly. Added asyncio.gather() to parallelize all 9 sequential calls in get_statistics().

Note: draft_list_service.add_to_list() verification GET was left in place — DraftList requires full nested Team/Player objects that aren't in the POST payload (only IDs). The N+1 loops in the cleanup methods are tracked in #89.

PR #112 opened: https://git.manticorum.com/cal/major-domo-v2/pulls/112 **Approach:** Eliminated redundant GET requests after POST/PUT in `custom_commands_service` and `help_commands_service` by returning API responses directly. Added `asyncio.gather()` to parallelize all 9 sequential calls in `get_statistics()`. Note: `draft_list_service.add_to_list()` verification GET was left in place — `DraftList` requires full nested `Team`/`Player` objects that aren't in the POST payload (only IDs). The N+1 loops in the cleanup methods are tracked in #89.
Claude added the
status/pr-open
label 2026-03-20 18:09:44 +00:00
cal closed this issue 2026-03-31 19:46:21 +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#95
No description provided.