From a1d96cc5d1287b01aaf087ac8208258e73e819d4 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 --- 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 b3ac362334..b596e1cd0b 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -361,9 +361,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 @@ -373,9 +373,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 @@ -1415,6 +1415,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.30.2