Optimize Budget model performance by preventing N+1 queries #2504
Reference in New Issue
Block a user
Delete Branch "optimize-budget-donut-chart-performance"
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?
Problem
The Budget model was suffering from N+1 query issues, leading to excessive database calls and performance degradation when rendering budget donut charts.
Before Optimization
budget_categoryand itscategoryseparatelySolution
index_byfor O(1) lookup.includes(:category)explicitly to ensure categories are preloaded, reducing query count.allocated_spendingmethod.After Optimization
budget_categoryImpact
This optimization is expected to significantly improve performance for users with many budget categories by reducing:
Testing
Added comprehensive test coverage to validate no regression in behavior and verified query count reduction.
Pull request closed