From 06c664be5fdd84476c9c8a339fc4a15fe8a7539f Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 18 Nov 2020 11:45:41 +0100 Subject: [PATCH] Bug 24488: perf - Move holds search out of the loop This will need attention from QA. Are we sure it's doing the same thing (especially the order by!) --- circ/pendingreserves.pl | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/circ/pendingreserves.pl b/circ/pendingreserves.pl index 69477bf6da..3ad34624d5 100755 --- a/circ/pendingreserves.pl +++ b/circ/pendingreserves.pl @@ -222,6 +222,20 @@ my $patrons_count = { } }; +my $all_holds = { + map { $_->biblionumber => $_ } @{ Koha::Holds->search( + {%where}, + { + prefetch => [ 'borrowernumber', 'itembib', 'biblio' ], + order_by => 'priority', + alias => 'reserve', + group_by => 'reserve.biblionumber', + } + )->as_list + } +}; + + # make final holds_info array and fill with info my @holds_info; foreach my $bibnum ( @biblionumbers ){ @@ -275,13 +289,7 @@ foreach my $bibnum ( @biblionumbers ){ $hold_info->{pull_count} = $pull_count; # get other relevant information - my $res_info = Koha::Holds->search( - { 'reserve.biblionumber' => $bibnum, %where }, - { prefetch => [ 'borrowernumber', 'itembib', 'biblio' ], - order_by => 'priority', - alias => 'reserve' - } - )->next; # get first item in results + my $res_info = $all_holds->{$bibnum}; $hold_info->{patron} = $res_info->patron; $hold_info->{item} = $res_info->item; $hold_info->{biblio} = $res_info->biblio; -- 2.20.1