From 635c1b6f72179c24f676927895f7929e7407202a Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 25 May 2022 14:44:50 +0000 Subject: [PATCH] Bug 30847: Don't get biblio/item info when placing holds MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The only bit we get form the hash is the rank and title We can simply fetch the biblio once to calculate no need to fetch all the info as we don't display or use it Signed-off-by: Owen Leonard Rebased-by: Victor Grousset/tuxayo Signed-off-by: Joonas Kylmälä Signed-off-by: Tomas Cohen Arazi --- opac/opac-reserve.pl | 86 ++++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 44 deletions(-) diff --git a/opac/opac-reserve.pl b/opac/opac-reserve.pl index 30fa544267..c4674e677a 100755 --- a/opac/opac-reserve.pl +++ b/opac/opac-reserve.pl @@ -130,46 +130,7 @@ $template->param( branch => $branch ); # # -# Build hashes of the requested biblio(item)s and items. -# -# - -my %biblioDataHash; # Hash of biblionumber to biblio/biblioitems record. -foreach my $biblioNumber (@biblionumbers) { - - my $biblioData = GetBiblioData($biblioNumber); - $biblioDataHash{$biblioNumber} = $biblioData; - - my $biblio = Koha::Biblios->find( $biblioNumber ); - next unless $biblio; - - my $marcrecord = $biblio->metadata->record; - - my $items = Koha::Items->search_ordered( - [ - biblionumber => $biblioNumber, - 'me.itemnumber' => { - -in => [ - $biblio->host_items->get_column('itemnumber') - ] - } - ], - { prefetch => [ 'issue', 'homebranch', 'holdingbranch' ] } - )->filter_by_visible_in_opac({ patron => $patron }); - - $biblioData->{items} = [$items->as_list]; # FIXME Potentially a lot in memory here! - - # Compute the priority rank. - $biblioData->{object} = $biblio; - my $reservecount = $biblio->holds->search({ found => [ {"!=" => "W"},undef] })->count; - $biblioData->{reservecount} = $reservecount; - $biblioData->{rank} = $reservecount + 1; -} - -# -# -# If this is the second time through this script, it -# means we are carrying out the hold request, possibly +# Here we are carrying out the hold request, possibly # with a specific item for each biblionumber. # # @@ -242,8 +203,6 @@ if ( $query->param('place_reserve') ) { $biblioNum = $item->biblionumber; } - my $biblioData = $biblioDataHash{$biblioNum}; - # Check for user supplied reserve date my $startdate; if ( C4::Context->preference('AllowHoldDateInFuture') @@ -257,7 +216,8 @@ if ( $query->param('place_reserve') ) { my $itemtype = $query->param('itemtype') || undef; $itemtype = undef if $itemNum; - my $rank = $biblioData->{rank}; + my $biblio = Koha::Biblios->find($biblioNum); + my $rank = $biblio->holds->search( { found => [ { "!=" => "W" }, undef ] } )->count + 1; if ( $item ) { $canreserve = 1 if CanItemBeReserved( $patron, $item, $branch )->{status} eq 'OK'; } @@ -296,7 +256,7 @@ if ( $query->param('place_reserve') ) { reservation_date => $startdate, expiration_date => $patron_expiration_date, notes => $notes, - title => $biblioData->{title}, + title => $biblio->title, itemnumber => $itemNum, found => undef, itemtype => $itemtype, @@ -311,6 +271,44 @@ if ( $query->param('place_reserve') ) { exit; } +# +# +# Build hashes of the requested biblio(item)s and items. +# +# + +my %biblioDataHash; # Hash of biblionumber to biblio/biblioitems record. +foreach my $biblioNumber (@biblionumbers) { + + my $biblioData = GetBiblioData($biblioNumber); + $biblioDataHash{$biblioNumber} = $biblioData; + + my $biblio = Koha::Biblios->find( $biblioNumber ); + next unless $biblio; + + my $marcrecord = $biblio->metadata->record; + + my $items = Koha::Items->search_ordered( + [ + biblionumber => $biblioNumber, + 'me.itemnumber' => { + -in => [ + $biblio->host_items->get_column('itemnumber') + ] + } + ], + { prefetch => [ 'issue', 'homebranch', 'holdingbranch' ] } + )->filter_by_visible_in_opac({ patron => $patron }); + + $biblioData->{items} = [$items->as_list]; # FIXME Potentially a lot in memory here! + + # Compute the priority rank. + $biblioData->{object} = $biblio; + my $reservecount = $biblio->holds->search({ found => [ {"!=" => "W"},undef] })->count; + $biblioData->{reservecount} = $reservecount; + $biblioData->{rank} = $reservecount + 1; +} + # # # Here we check that the borrower can actually make reserves Stage 1. -- 2.39.5