From 35e3678f13e47b5e9596b4a4d62cb050e1832760 Mon Sep 17 00:00:00 2001 From: Francesco Rivetti Date: Tue, 14 Feb 2017 11:13:51 +0100 Subject: [PATCH] Bug 17941 avoid scanning the full cartesian product when a item match a borrower, there is no point in checking the other borrowers Signed-off-by: Mark Tompsett Signed-off-by: Jonathan Druart Signed-off-by: Kyle M Hall --- C4/Circulation.pm | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index e2cd6261c3..b6ca23deb6 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2677,24 +2677,23 @@ sub CanBookBeRenewed { # can be filled with available items. We can get the union of the sets simply # by pushing all the elements onto an array and removing the duplicates. my @reservable; - foreach my $b (@borrowernumbers) { - my ($borr) = C4::Members::GetMember( borrowernumber => $b); - foreach my $i (@itemnumbers) { - my $item = GetItem($i); - if ( !IsItemOnHoldAndFound($i) - && IsAvailableForItemLevelRequest( $item, $borr ) - && CanItemBeReserved( $b, $i ) ) - { - push( @reservable, $i ); + my %borrowers; + ITEM: foreach my $i (@itemnumbers) { + my $item = GetItem($i); + next if IsItemOnHoldAndFound($i); + for my $b (@borrowernumbers) { + my $borr = $borrowers{$b}//= C4::Members::GetMember(borrowernumber => $b); + next unless IsAvailableForItemLevelRequest($item, $borr); + next unless CanItemBeReserved($b,$i); + + push @reservable, $i; + if (@reservable >= @borrowernumbers) { + $resfound = 0; + last ITEM; } + last; } } - - @reservable = uniq(@reservable); - - if ( @reservable >= @borrowernumbers ) { - $resfound = 0; - } } } return ( 0, "on_reserve" ) if $resfound; # '' when no hold was found -- 2.39.5