-
-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
Summary
CalendarBalanceListener calls flush() inside Doctrine entity listeners (postPersist, postUpdate, postRemove). This pattern can cause nested flush side-effects, make transactions harder to reason about, and can severely degrade performance during bulk operations (imports, future recurring generators).
Affected code
backend/src/EventListener/CalendarBalanceListener.php
Current behavior
Every Expense persist/update/remove triggers a listener that updates Calendar.balance and immediately flushes.
Problems
- Potential nested flush / UnitOfWork edge cases.
- Poor performance for bulk inserts/updates (flush per row).
- Harder to test/debug because side effects happen implicitly.
Suggested approaches
Option A (recommended):
- Move balance recomputation/update to the service layer where Expense changes occur; flush once per request/batch.
Option B:
- Use Doctrine
onFlush/preFlushand schedule the calendar update without triggering a nested flush.
Option C:
- Remove materialized
Calendar.balanceand compute on-demand (may be too invasive).
Acceptance criteria
- No
flush()calls occur inside entity listeners. - Balance remains correct after create/update/delete and after bulk import.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels