https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=28530 --- Comment #194 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 192494 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=192494&action=edit Bug 28530: (QA follow-up) Fix N+1 query performance issue Refactored lowest_ratio_library() to eliminate the N+1 query problem by using aggregated queries with GROUP BY instead of per-branch queries. Performance improvement: - Before: O(3n) queries where n = number of branches with float limits Example: 20 branches = 60 database queries - After: O(3) queries regardless of number of branches Example: 20 branches = 3 database queries The optimization uses three aggregated queries: 1. Single query with GROUP BY to get item counts at all branches 2. Single query with GROUP BY to get in-transit-to counts for all branches 3. Single query with GROUP BY to get in-transit-from counts for all branches Results are combined in memory to calculate ratios, maintaining identical logic and behavior while dramatically improving database efficiency. Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> -- You are receiving this mail because: You are watching all bug changes.