From 457a470e9bc997c6557cc6b8e1608aa2dc239978 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Nyl=C3=A9n?= Date: Thu, 29 Apr 2021 11:32:05 +0200 Subject: [PATCH 2/2] Bug 26587: Cache authorised values in C4::Items::GetItemsInfo to improve performance This patch caches the authorised value descriptions in C4::Items::GetItemsInfo while looping through items. Improves performance for biblios with very large number of items. To test: 1. Have a biblio with many items (1000's). 2. View in staff (detail.pl) and opac (opac-detail.pl). Note how long it takes to load. 3. Apply patch. 4. Repeat 2. Note that pages load faster. Sponsored-by: Lund University Library --- C4/Items.pm | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index 726c7e4cd8..9875ce7598 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -770,18 +770,35 @@ sub GetItemsInfo { my $descriptions; # get notforloan complete status if applicable - $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => $data->{frameworkcode}, kohafield => 'items.notforloan', authorised_value => $data->{itemnotforloan} }); - $data->{notforloanvalue} = $descriptions->{lib} // ''; - $data->{notforloanvalueopac} = $descriptions->{opac_description} // ''; - + if (exists $av_cache->{$data->{frameworkcode}}->{'items.notforloan'}->{$data->{itemnotforloan}} ){ + $data->{notforloanvalue} = $av_cache->{$data->{frameworkcode}}->{'items.notforloan'}->{$data->{itemnotforloan}}->{lib}; + $data->{notforloanvalueopac} = $av_cache->{$data->{frameworkcode}}->{'items.notforloan'}->{$data->{itemnotforloan}}->{opac_description}; + }else{ + $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => $data->{frameworkcode}, kohafield => 'items.notforloan', authorised_value => $data->{itemnotforloan} }); + $data->{notforloanvalue} = $descriptions->{lib} // ''; + $data->{notforloanvalueopac} = $descriptions->{opac_description} // ''; + $av_cache->{$data->{frameworkcode}}->{'items.notforloan'}->{$data->{itemnotforloan}}->{lib} = $data->{notforloanvalue}; + $av_cache->{$data->{frameworkcode}}->{'items.notforloan'}->{$data->{itemnotforloan}}->{opac_description} = $data->{notforloanvalueopac}; + } # get restricted status and description if applicable - $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => $data->{frameworkcode}, kohafield => 'items.restricted', authorised_value => $data->{restricted} }); - $data->{restrictedvalue} = $descriptions->{lib} // ''; - $data->{restrictedvalueopac} = $descriptions->{opac_description} // ''; - + if (exists $av_cache->{$data->{frameworkcode}}->{'items.restricted'}->{$data->{restricted}} ) { + $data->{restrictedvalue} = $av_cache->{$data->{frameworkcode}}->{'items.restricted'}->{$data->{restricted}}->{lib}; + $data->{restrictedvalueopac} = $av_cache->{$data->{frameworkcode}}->{'items.restricted'}->{$data->{restricted}}->{opac_description}; + }else{ + $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => $data->{frameworkcode}, kohafield => 'items.restricted', authorised_value => $data->{restricted} }); + $data->{restrictedvalue} = $descriptions->{lib} // ''; + $data->{restrictedvalueopac} = $descriptions->{opac_description} // ''; + $av_cache->{$data->{frameworkcode}}->{'items.restricted'}->{$data->{restricted}}->{lib} = $data->{restrictedvalue} ; + $av_cache->{$data->{frameworkcode}}->{'items.restricted'}->{$data->{restricted}}->{opac_description} = $data->{restrictedvalueopac}; + } # my stack procedures - $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => $data->{frameworkcode}, kohafield => 'items.stack', authorised_value => $data->{stack} }); - $data->{stack} = $descriptions->{lib} // ''; + if (exists $av_cache->{$data->{frameworkcode}}->{'items.stack'}->{$data->{stack}} ) { + $data->{stack} = $av_cache->{$data->{frameworkcode}}->{'items.stack'}->{$data->{stack}}->{lib}; + }else{ + $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => $data->{frameworkcode}, kohafield => 'items.stack', authorised_value => $data->{stack} }); + $data->{stack} = $descriptions->{lib} // ''; + $av_cache->{$data->{frameworkcode}}->{'items.stack'}->{$data->{stack}}->{lib} = $data->{stack}; + } # Find the last 3 people who borrowed this item. my $sth2 = $dbh->prepare("SELECT * FROM old_issues,borrowers -- 2.25.1