From d54e32fa3a98950af84b3e308f84b4d5adb520c5 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 18 Nov 2020 11:14:10 +0100 Subject: [PATCH] Bug 24488: perf - move patrons_count out of the loop Signed-off-by: Michal Denar Signed-off-by: Josef Moravec Signed-off-by: Marcel de Rooy Signed-off-by: Jonathan Druart --- circ/pendingreserves.pl | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/circ/pendingreserves.pl b/circ/pendingreserves.pl index 0bc6995768..9cad99ab8f 100755 --- a/circ/pendingreserves.pl +++ b/circ/pendingreserves.pl @@ -209,6 +209,18 @@ foreach my $item ( @all_items ) { push @{$all_items->{$item->biblionumber}}, $item; } +# patrons count per biblio +my $patrons_count = { + map { $_->{biblionumber} => $_->{patrons_count} } @{ Koha::Holds->search( + {}, + { + select => [ 'biblionumber', { count => { distinct => 'borrowernumber' } } ], + as => [qw( biblionumber patrons_count )], + group_by => [qw( biblionumber )] + }, + )->unblessed + } +}; # make final reserves hash and fill with info my $reserves; @@ -253,13 +265,9 @@ foreach my $bibnum ( @biblionumbers ){ $reserves->{$bibnum}->{items_count} = $items_count; # patrons with holds - my $patrons_count = Koha::Holds->search( - { biblionumber => $bibnum }, - { distinct => 1, columns => qw(me.borrowernumber) } - )->count; - $reserves->{$bibnum}->{patrons_count} = $patrons_count; + $hold_info->{patrons_count} = $patrons_count->{$bibnum}; - my $pull_count = $items_count <= $patrons_count ? $items_count : $patrons_count; + my $pull_count = $items_count <= $patrons_count->{$bibnum} ? $items_count : $patrons_count->{$bibnum}; if ( $pull_count == 0 ) { delete($reserves->{$bibnum}); next; -- 2.39.5