[Koha-bugs] [Bug 24185] 'If all unavailable' state for 'on shelf holds' makes holds page very slow if there's a lot of items

bugzilla-daemon at bugs.koha-community.org bugzilla-daemon at bugs.koha-community.org
Tue Dec 10 13:36:55 CET 2019


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

Andrew Nugged <nugged at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #96080|0                           |1
        is obsolete|                            |

--- Comment #4 from Andrew Nugged <nugged at gmail.com> ---
Created attachment 96151
  -->
https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=96151&action=edit
Bug 24185: Make holds page fast when 'on shelf holds' set to 'If all
unavailable'

When "reserve/request.pl -> C4/Reserves.pm::IsAvailableForItemLevelRequest"
called many times with hundred of items and "on shelf holds" parameter set to
"If all unavailable" for these items+patron, it goes very slow.

This happens because in subloop there are re-checking if all other item
unavailable so it is O(n^2) and it re-checks each time a lot of the same info
for each item with repeating DB/data requests, these three:
  - GetBranchItemRule (per item type)
  - IsItemOnHoldAndFound (per item)
  - notforloan (per item)

Fix: Use in-variable cache in upper-level subroutine before entering the first
"items" loop and passing that hash reference down into subs to cache these
three values by keys per-item and per-item-type.

It is simplest way to make it fast without re-thinking pretty complicated whole
algorithm and business logic, and, when tested by speed it gave big improvement
in execution time.
Also "$can_item_be_reserved->{status} eq 'OK'" moved in "&&" before
IsAvailableForItemLevelRequest call to cut away if it false before calling to
subroutine.

How to reproduce:

1) on fresh installed kohadevbox create/import one book,
record that biblionumber for later use it in down below,

2) add 100 items for that book for some library,

3) find some patron, that patron's card number we will
use as a borrower down below to open holds page,

4) check for the rule or set up single circulation rule
in admin "/cgi-bin/koha/admin/smart-rules.pl",
so that rule will match above book items/library/patron,
check that rule to have non-zero number of holds (total, daily, count) allowed,
and, IMPORTANT: set up "On shelf holds allowed" to "If all unavailable",
("item level holds" doesn't matter).

5) open "Home > Catalog > THAT_BOOK > Place a hold on THAT_BOOK" page
("holds" tab), and enter patron code in the search field,
or you can create direct link by yourself, for example in my case it was:
/cgi-bin/koha/reserve/request.pl?biblionumber=4&findborrower=23529000686353

6) it should be pretty long page generation time.

I tested on my computer in VirtualBox for this page generation times,
(stats below is for many runs and smallest value taken from similar in a
repetition)

(NOT buggy clause, just example how it fast when it not enters that "subloop"):
*** "On shelf holds allowed" != "If all unavailable":
  100 items:    5 seconds,
  200 items:   10 seconds,
  300 items:   11 seconds,

(buggy clause):
*** "On shelf holds allowed" == "If all unavailable":
  100 items:    50 seconds,
  200 items:   3.1 minutes,
  300 items:   7.0 minutes,

(same as above clause but fixed with caching in hash):
*** "On shelf holds allowed" == "If all unavailable" with cache:
  100 items:    7 seconds,
  200 items:   20 seconds,
  300 items:   38 seconds,

Upper last one block with times with this in-var-cache solution.

-- 
You are receiving this mail because:
You are watching all bug changes.


More information about the Koha-bugs mailing list