From bc853c2db355d49230e0336406b3880f91745ba6 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 14 Mar 2016 18:16:36 +0000 Subject: [PATCH] Bug 8483 - Speed improvements --- Koha/Checkout.pm | 7 +++---- Koha/Item.pm | 14 ++++++-------- Koha/Patron.pm | 5 ++++- t/db_dependent/Members/GetAllIssues.t | 10 +++++++++- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/Koha/Checkout.pm b/Koha/Checkout.pm index e96b6ad..936a234 100644 --- a/Koha/Checkout.pm +++ b/Koha/Checkout.pm @@ -52,11 +52,10 @@ deleted item. sub item { my ( $self, $params ) = @_; - my $item = Koha::Items->search( { itemnumber => $self->itemnumber() } )->next(); + $self->{_item} ||= Koha::Item->_new_from_dbic( $self->_result()->item ); + $self->{_item} ||= Koha::Deleted::Items->find( { itemnumber => $self->itemnumber() } ) if ( $params->{deleted} ); - $item ||= Koha::Deleted::Items->search( { itemnumber => $self->itemnumber() } )->next() if ( $params->{deleted} ); - - return $item || undef; + return $self->{_item}; } =head3 type diff --git a/Koha/Item.pm b/Koha/Item.pm index 14f9853..f2e258f 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -126,11 +126,10 @@ deleted biblio. sub biblio { my ( $self, $params ) = @_; - my $biblio = Koha::Biblios->search( { biblionumber => $self->biblionumber() } )->next(); + $self->{_biblio} ||= Koha::Biblio->_new_from_dbic( $self->_result()->biblio ); + $self->{_biblio} ||= Koha::Deleted::Biblios->find( { biblionumber => $self->biblionumber() } ) if ( $params->{deleted} ); - $biblio ||= Koha::Deleted::Biblios->search( { biblionumber => $self->biblionumber() } )->next() if ( $params->{deleted} ); - - return $biblio || undef; + return $self->{_biblio}; } =head3 biblioitem @@ -148,11 +147,10 @@ deleted biblioitem. sub biblioitem { my ( $self, $params ) = @_; - my $biblioitem = Koha::BiblioItems->search( { biblionumber => $self->biblionumber() } )->next(); - - $biblioitem ||= Koha::Deleted::BiblioItems->search( { biblionumber => $self->biblionumber() } )->next() if ( $params->{deleted} ); + $self->{_biblioitem} ||= Koha::BiblioItem->_new_from_dbic( $self->_result()->biblioitem ); + $self->{_biblioitem} ||= Koha::Deleted::BiblioItems->find( { biblionumber => $self->biblionumber() } ) if ( $params->{deleted} ); - return $biblioitem || undef; + return $self->{_biblioitem}; } =head3 type diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 4f52fc3..4e6eb76 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -114,7 +114,10 @@ sub all_checkouts { borrowernumber => $self->borrowernumber(), }, { - order_by => { "-$order_by_sort" => $order_by_column } + order_by => { "-$order_by_sort" => $order_by_column }, + prefetch => { + 'item' => 'biblio' + } } ); diff --git a/t/db_dependent/Members/GetAllIssues.t b/t/db_dependent/Members/GetAllIssues.t index 62eae89..723b8f4 100644 --- a/t/db_dependent/Members/GetAllIssues.t +++ b/t/db_dependent/Members/GetAllIssues.t @@ -2,7 +2,7 @@ use Modern::Perl; -use Test::More tests => 16; +use Test::More tests => 17; use Test::MockModule; use C4::Biblio; @@ -93,4 +93,12 @@ $issues = C4::Members::GetAllIssues($borrowernumber2); is( @$issues, 1, 'GetAllIssues returns the correct number of elements' ); is( $issues->[0]->{itemnumber}, $itemnumber3, '' ); +my @itemnumbers; +for my $i ( 1 .. 500 ) { + my $in = AddItem( { barcode => $i, %item_branch_infos }, $biblionumber1 ); + AddIssue( $borrower1, $i ); +} +$issues = C4::Members::GetAllIssues($borrowernumber1); +is( @$issues, 502, 'GetAllIssues returns the correct number of elements' ); + $dbh->rollback(); -- 2.1.4