https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43124 --- Comment #9 from Andrew Fuerste-Henry <andrew@bywatersolutions.com> --- Created attachment 211414 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=211414&action=edit Bug 43124: Prefetch patron/biblio context to avoid per-item queries Koha::Item::Availability::Hold->check still issued its own DB query per item for item_already_on_hold, already_possession, and recall (all patron-scoped, not item-scoped - the same patron's held/checked-out/ recalled item sets don't vary across items on the same record), and recomputed age restriction (a biblio-scoped result) via a fresh $item->biblio fetch on every item. Added optional held_itemnumbers/recalled_itemnumbers (hashref of itemnumbers), checked_out_biblionumbers (hashref of biblionumbers, since already_possession applies to any item of a biblio the patron has checked out) and age_restriction_ok (boolean) params to check(), falling back to the existing per-item queries when not supplied so every other caller of this class is unaffected. age_restriction_ok is only passed for items of the biblio being checked: host-record (analytics) items belong to another biblio and keep the per-item check. Koha::Biblio::Availability::Hold now computes these once before its item loop and passes them into every per-item check, collapsing what were 3N+ queries down to a handful regardless of item count. can_be_transferred (genuinely item-homebranch-specific) is instead memoized per request via Koha::Cache::Memory::Lite, keyed on the branch/ itemtype-or-ccode combination that determines it, opt-in via a new cache_transfers flag (off by default, matching the existing cache_counts pattern, since a caller that creates/deletes transfer limits between calls must see a fresh result). Added a query-count-at-scale test (10 vs 100 items, patron holding every item) asserting the query delta stays small rather than growing with item count - the concrete acceptance criterion from the original architecture proposal for this bug. Test plan: 1. Apply patch 2. Run: $ ktd --shell k$ prove t/db_dependent/Koha/Patron/Availability/Hold.t \ t/db_dependent/Koha/Item/Availability/Hold.t \ t/db_dependent/Koha/Biblio/Availability/Hold.t \ t/db_dependent/Reserves.t t/db_dependent/Holds.t \ t/db_dependent/Reserves/MultiplePerRecord.t \ t/db_dependent/ILSDI_Services.t => SUCCESS: All tests pass, including the new query-count assertion! 3. Sign off :-D Signed-off-by: Bob Bennhoff <bbennhoff@clicweb.org> -- You are receiving this mail because: You are watching all bug changes.