From 9e780aaf84ad8d33c96a81daa97bb8ab37aa61a8 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 10 Mar 2023 12:40:30 +0000 Subject: [PATCH] Bug 33497: Use 'host_items' param to fetch all items at once This patch adjusts the detail page to fetch items and host items together, and prefetches transfers and checkouts To test: 1 - Enable easy analytics 2 - Attach some items to a bib 3 - Checkout an item on the bib 4 - View the details page 5 - Apply patch 6 - View details page, confirm nothing has changed Signed-off-by: David Nind Signed-off-by: Jonathan Druart Signed-off-by: Tomas Cohen Arazi (cherry picked from commit 2cf00f1a49a7b9f8d5ca105e2dd1add5d5d95198) Signed-off-by: Martin Renvoize (cherry picked from commit dc273a8dfe384b7c847a23b842f1dde601537d82) Signed-off-by: Matt Blenkinsop --- catalogue/detail.pl | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/catalogue/detail.pl b/catalogue/detail.pl index f8b6d04237..3cd9dd7cb9 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -193,23 +193,16 @@ my $itemtypes = { map { $_->itemtype => $_ } @{ Koha::ItemTypes->search_with_loc my $all_items = $biblio->items->search_ordered; my @items; my $patron = Koha::Patrons->find( $borrowernumber ); -while ( my $item = $all_items->next ) { - push @items, $item - unless $item->itemlost - && $patron->category->hidelostitems - && !$showallitems; -} +$params->{ itemlost } = 0 if $patron->category->hidelostitems && !$showallitems; +my $items = $biblio->items({ host_items => 1 })->search_ordered( $params, { prefetch => ['issue','branchtransfers'] } ); # flag indicating existence of at least one item linked via a host record -my $hostrecords; -# adding items linked via host biblios -my $hostitems = $biblio->host_items; -if ( $hostitems->count ) { - $hostrecords = 1; - push @items, $hostitems->as_list; -} +my $hostrecords = $biblio->host_items->count; my $dat = &GetBiblioData($biblionumber); +$dat->{'count'} = $biblio->items({ host_items => 1 })->count; +$dat->{'showncount'} = $items->count; +$dat->{'hiddencount'} = $dat->{'count'} - $dat->{'showncount'}; #is biblio a collection and are bundles enabled my $leader = $marc_record->leader(); @@ -365,7 +358,7 @@ if ($currentbranch and C4::Context->preference('SeparateHoldings')) { my $separatebranch = C4::Context->preference('SeparateHoldingsBranch') || 'homebranch'; my ( $itemloop_has_images, $otheritemloop_has_images ); -foreach my $item (@items) { +while ( my $item = $items->next ) { my $itembranchcode = $item->$separatebranch; my $item_info = $item->unblessed; @@ -539,7 +532,7 @@ $template->param( materials => $materials_flag, ); -if (C4::Context->preference("AlternateHoldingsField") && scalar @items == 0) { +if (C4::Context->preference("AlternateHoldingsField") && scalar $items->count == 0) { my $fieldspec = C4::Context->preference("AlternateHoldingsField"); my $subfields = substr $fieldspec, 3; my $holdingsep = C4::Context->preference("AlternateHoldingsSeparator") || ' '; -- 2.39.2