@@ -, +, @@ is very inefficient, causing timeouts on records with large numbers of holds/items --- Koha/Template/Plugin/Branches.pm | 40 +++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 8 deletions(-) --- a/Koha/Template/Plugin/Branches.pm +++ a/Koha/Template/Plugin/Branches.pm @@ -25,6 +25,7 @@ use base qw( Template::Plugin ); use C4::Koha; use C4::Context; +use Koha::Caches; use Koha::Libraries; sub GetName { @@ -105,6 +106,9 @@ sub pickup_locations { my $selected = $params->{selected}; my @libraries; + my $cache = Koha::Caches->get_instance(); + my $cache_key; + if(defined $search_params->{item} || defined $search_params->{biblio}) { my $item = $search_params->{'item'}; my $biblio = $search_params->{'biblio'}; @@ -117,22 +121,41 @@ sub pickup_locations { if ($item) { $item = Koha::Items->find($item) unless ref($item) eq 'Koha::Item'; - @libraries = @{ $item->pickup_locations( { patron => $patron } ) } - if defined $item; + + if ( defined $item ) { + $cache_key = "I" . $item->homebranch . "-" . $patron->branchcode; + my $result = $cache->get_from_cache($cache_key); + if ( $result ) { + @libraries = @{$result}; + } else { + @libraries = @{ $item->pickup_locations( { patron => $patron } ) }; + @libraries = map { $_->unblessed } @libraries; + } + } } elsif ($biblio) { $biblio = Koha::Biblios->find($biblio) unless ref($biblio) eq 'Koha::Biblio'; - @libraries = @{ $biblio->pickup_locations( { patron => $patron } ) } - if defined $biblio; + + if ( defined $biblio ) { + $cache_key = "B" . $biblio->id . "-" . $patron->branchcode; + my $result = $cache->get_from_cache($cache_key); + if ( $result ) { + @libraries = @{$result}; + } else { + @libraries = @{ $biblio->pickup_locations( { patron => $patron } ) }; + @libraries = map { $_->unblessed } @libraries; + } + } } } - @libraries = Koha::Libraries->search( { pickup_location => 1 }, - { order_by => ['branchname'] } )->as_list - unless @libraries; + unless ( @libraries ) { + @libraries = Koha::Libraries->search( { pickup_location => 1 }, + { order_by => ['branchname'] } )->as_list; - @libraries = map { $_->unblessed } @libraries; + @libraries = map { $_->unblessed } @libraries; + } for my $l (@libraries) { if ( defined $selected and $l->{branchcode} eq $selected @@ -144,6 +167,7 @@ sub pickup_locations { } } + $cache->set_in_cache( $cache_key, \@libraries ); return \@libraries; } --