https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43124

--- Comment #1 from Martin Renvoize (ashimema) 
<[email protected]> ---
Created attachment 202393
  -->
https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=202393&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/checked_out_itemnumbers/recalled_itemnumbers
(hashref) 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. 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

-- 
You are receiving this mail because:
You are watching all bug changes.
_______________________________________________
Koha-bugs mailing list -- [email protected]
To unsubscribe send an email to [email protected]
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/

Reply via email to