Eliminate N+1 queries in post_transactions
#25
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#25
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/transactions.py:126-133— For each transaction in a batch, 3 individual DB queries validate teams and players. For a 50-move batch = 150 queries. Same pattern inpost_results,post_schedules,post_batstats. All should useTeam.id << [list]to fetch in a single query.Priority: medium | Labels: performance
PR #52 addresses this: #52
Fix approach: Before the validation loop in each endpoint, all required IDs are collected into sets and fetched with a single
WHERE id IN (...)query. The loop then checks membership in the resulting Python sets instead of issuing a DB query per row.post_transactions: 3N → 2 queries (team IDs + player IDs)post_results/post_schedules: 2N → 1 query (combined away+home team IDs)post_batstats: 2N → 2 queries (team IDs + player IDs)