Bug 24185: Make holds page faster: Preparatory refactoring
This is just refactoring. extracting logically independent code
to separate sub + tests update. No logic change yet.
Searching for "any_available" item among all biblionumber items was done
inside of "elsif on_shelf_holds == 2", and it is logically very independent
piece of code (this "@items" loop), it needs just biblionumber and patron
as parameters so it can be extracted into separate subroutine, and
later also called/reused from somewhere else.
This ability to call from another place also made for future patch
to remove O(n^2) problem with nested loops.
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
is($is,1,"Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, One item is available at different library, not holdable = none available => the hold is allowed at item level");
is($is,1,"Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, One item is available at home library, holdable = one available => the hold is not allowed at item level");
#Adding a rule for the item's home library affects the availability for a borrower from another library because ReservesControlBranch is set to ItemHomeLibrary
$is=ItemsAnyAvailableForHold({biblionumber=>$biblionumber,patron=>$patron1});# patron1 in library A, library A 0 items, library B 1 item
is($is,1,"Items availability: hold allowed from any library for library B + ReservesControlBranch=ItemHomeLibrary + one item is available at different library");
is($is,0,"Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, One item is available at different library, holdable = one available => the hold is not allowed at item level");
$is=ItemsAnyAvailableForHold({biblionumber=>$biblionumber,patron=>$patron1});# patron1 in library A, library A 0 items, library B 1 item
is($is,0,"Items availability: hold allowed from any library for library B + ReservesControlBranch=PatronLibrary + one item is available at different library");
is($is,1,"Hold allowed from home library + ReservesControlBranch=PatronLibrary, One item is available at different library, not holdable = none available => the hold is allowed at item level");
#Adding a rule for the patron's home library affects the availability for an item from another library because ReservesControlBranch is set to PatronLibrary
$is=ItemsAnyAvailableForHold({biblionumber=>$biblionumber,patron=>$patron1});# patron1 in library A, library A 0 items, library B 1 item
is($is,1,"Items availability: hold allowed from any library for library A + ReservesControlBranch=PatronLibrary + one item is available at different library");
is($is,0,"Hold allowed from home library + ReservesControlBranch=PatronLibrary, One item is available at different library, holdable = one available => the hold is not allowed at item level");
is($is,0,"Hold allowed from any library + ReservesControlBranch=ItemHomeLibrary, One item is available at the diff library, holdable = 1 available => the hold is not allowed at item level");
is($is,0,"Hold allowed from any library + ReservesControlBranch=PatronLibrary, One item is available at the diff library, holdable = 1 available => the hold is not allowed at item level");
}
};
subtest'Item is available at the same library'=>sub{
is($is,0,"Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, One item is available at the same library, holdable = 1 available => the hold is not allowed at item level");
is($is,0,"Hold allowed from home library + ReservesControlBranch=PatronLibrary, One item is available at the same library, holdable = 1 available => the hold is not allowed at item level");
is($is,0,"Hold allowed from any library + ReservesControlBranch=ItemHomeLibrary, One item is available at the same library, holdable = 1 available => the hold is not allowed at item level");
is($is,0,"Hold allowed from any library + ReservesControlBranch=PatronLibrary, One item is available at the same library, holdable = 1 available => the hold is not allowed at item level");