From e627b437dc54a9494204f5d5ea7e989261d74cf3 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 12 Aug 2022 15:33:45 +0000 Subject: [PATCH] Bug 31314: (QA follow-up) Prefetch and make routines use result objects This reduces lookups for the related items that we now fetch in the templates Signed-off-by: Nick Clemens Signed-off-by: Tomas Cohen Arazi --- Koha/Item.pm | 9 +++++---- opac/opac-reserve.pl | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Koha/Item.pm b/Koha/Item.pm index 06e4152949..653eb73d79 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -362,9 +362,9 @@ sub effective_itemtype { sub home_branch { my ($self) = @_; - $self->{_home_branch} ||= Koha::Libraries->find( $self->homebranch() ); + my $hb_rs = $self->_result->homebranch; - return $self->{_home_branch}; + return Koha::Library->_new_from_dbic( $hb_rs ); } =head3 holding_branch @@ -374,9 +374,9 @@ sub home_branch { sub holding_branch { my ($self) = @_; - $self->{_holding_branch} ||= Koha::Libraries->find( $self->holdingbranch() ); + my $hb_rs = $self->_result->holdingbranch; - return $self->{_holding_branch}; + return Koha::Library->_new_from_dbic( $hb_rs ); } =head3 biblio @@ -1421,6 +1421,7 @@ sub to_api_mapping { sub itemtype { my ( $self ) = @_; + return Koha::ItemTypes->find( $self->effective_itemtype ); } diff --git a/opac/opac-reserve.pl b/opac/opac-reserve.pl index 26a4d8c23b..20f67e8313 100755 --- a/opac/opac-reserve.pl +++ b/opac/opac-reserve.pl @@ -155,12 +155,13 @@ foreach my $biblioNumber (@biblionumbers) { my $items = Koha::Items->search_ordered( [ biblionumber => $biblioNumber, - itemnumber => { + '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! -- 2.39.5