Replace row-by-row DELETE with bulk DELETE in career recalculation #77

Open
opened 2026-03-27 04:06:47 +00:00 by cal · 1 comment
Owner

Problem

In app/db_engine.py lines 1373-1408 and 1434-1465, career recalculation loads ALL rows then deletes them one at a time:

delete_lines = BattingCareer.select()
for line in delete_lines:
    line.delete_instance()

On PostgreSQL, this means N+1 round-trips instead of a single DELETE FROM.

Fix

Replace with bulk delete: BattingCareer.delete().execute() (same for PitchingCareer and FieldingCareer).

Severity

Medium — unnecessary performance cost.

## Problem In `app/db_engine.py` lines 1373-1408 and 1434-1465, career recalculation loads ALL rows then deletes them one at a time: ```python delete_lines = BattingCareer.select() for line in delete_lines: line.delete_instance() ``` On PostgreSQL, this means N+1 round-trips instead of a single `DELETE FROM`. ## Fix Replace with bulk delete: `BattingCareer.delete().execute()` (same for `PitchingCareer` and `FieldingCareer`). ## Severity Medium — unnecessary performance cost.
Claude added the
ai-working
label 2026-03-27 08:01:11 +00:00
Claude removed the
ai-working
label 2026-03-27 08:03:12 +00:00
Collaborator

PR #92 opens the fix: #92

Replaced the three row-by-row delete loops in BattingCareer.recalculate(), PitchingCareer.recalculate(), and FieldingCareer.recalculate() with single bulk Model.delete().execute() calls — one round-trip instead of N.

PR #92 opens the fix: https://git.manticorum.com/cal/major-domo-database/pulls/92 Replaced the three row-by-row delete loops in `BattingCareer.recalculate()`, `PitchingCareer.recalculate()`, and `FieldingCareer.recalculate()` with single bulk `Model.delete().execute()` calls — one round-trip instead of N.
Claude added the
ai-pr-opened
label 2026-03-27 08:03:20 +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-database#77
No description provided.