@@ -, +, @@ is very inefficient, causing timeouts on records with large numbers of holds/items --- Koha/Template/Plugin/Branches.pm | 12 ++++++++++++ 1 file changed, 12 insertions(+) --- a/Koha/Template/Plugin/Branches.pm +++ a/Koha/Template/Plugin/Branches.pm @@ -99,12 +99,15 @@ sub InIndependentBranchesMode { return ( not C4::Context->preference("IndependentBranches") or C4::Context::IsSuperLibrarian ); } +our $cached_pickup_locations = {}; sub pickup_locations { my ( $self, $params ) = @_; my $search_params = $params->{search_params} || {}; my $selected = $params->{selected}; my @libraries; + my $cache_key; + if(defined $search_params->{item} || defined $search_params->{biblio}) { my $item = $search_params->{'item'}; my $biblio = $search_params->{'biblio'}; @@ -117,12 +120,20 @@ sub pickup_locations { if ($item) { $item = Koha::Items->find($item) unless ref($item) eq 'Koha::Item'; + + $cache_key = "I" . $item->homebranch . "-" . $patron->branchcode; + return $cached_pickup_locations->{$cache_key} if defined $cached_pickup_locations->{$cache_key}; + @libraries = @{ $item->pickup_locations( { patron => $patron } ) } if defined $item; } elsif ($biblio) { $biblio = Koha::Biblios->find($biblio) unless ref($biblio) eq 'Koha::Biblio'; + + $cache_key = "B" . $biblio->id . "-" . $patron->branchcode; + return $cached_pickup_locations->{$cache_key} if defined $cached_pickup_locations->{$cache_key}; + @libraries = @{ $biblio->pickup_locations( { patron => $patron } ) } if defined $biblio; } @@ -144,6 +155,7 @@ sub pickup_locations { } } + $cached_pickup_locations->{$cache_key} = \@libraries; return \@libraries; } --