Fix N+1 query in get_custom_commands
#26
Labels
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/major-domo-database#26
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?
app/routers_v3/custom_commands.py:294-296— For each command, a separate SELECT for creator is issued. With 25 commands per page = 26 queries. The initial join already fetches creator fields.Priority: medium | Labels: performance
Fixed in PR #51.
Approach: Expanded the JOIN SELECT in
get_custom_commandsto also fetchcreator.created_at,creator.total_commands, andcreator.active_commands(in addition to the already-joineddiscord_id,username,display_name). Replaced the per-rowSELECT * FROM custom_command_creators WHERE id = %swith buildingCustomCommandCreatorModeldirectly from the joined data. Result: 26 queries → 2 queries for a 25-command page.