@@ -, +, @@ C4::Items::GetItemsInfo to improve performance --- C4/Items.pm | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) --- a/C4/Items.pm +++ a/C4/Items.pm @@ -758,9 +758,13 @@ sub GetItemsInfo { my $i = 0; my @results; my $serial; - my $userenv = C4::Context->userenv; my $want_not_same_branch = C4::Context->preference("IndependentBranches") && !C4::Context->IsSuperLibrarian(); + + my $av_cache = {};# Initializing a chache for auth. values looked up in loops below + foreach my $itemcol (qw/notforloan restricted stack/){ + $av_cache->{$itemcol} = {}; + } while ( my $data = $sth->fetchrow_hashref ) { if ( $data->{borrowernumber} && $want_not_same_branch) { $data->{'NOTSAMEBRANCH'} = $data->{'bcode'} ne $userenv->{branch}; @@ -770,18 +774,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->{notforloan}->{$data->{itemnotforloan} // ''} ){ + $data->{notforloanvalue} = $av_cache->{notforloan}->{$data->{itemnotforloan} // ''}->{lib}; + $data->{notforloanvalueopac} = $av_cache->{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->{notforloan}->{$data->{itemnotforloan} // ''}->{lib} = $data->{notforloanvalue}; + $av_cache->{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->{restricted}->{$data->{restricted} // ''} ) { + $data->{restrictedvalue} = $av_cache->{restricted}->{$data->{restricted} // ''}->{lib}; + $data->{restrictedvalueopac} = $av_cache->{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->{restricted}->{$data->{restricted} // ''}->{lib} = $data->{restrictedvalue} ; + $av_cache->{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->{stack}->{$data->{stack} // ''} ) { + $data->{stack} = $av_cache->{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->{stack}->{$data->{stack}}->{lib} = $data->{stack}; + } # Find the last 3 people who borrowed this item. my $sth2 = $dbh->prepare("SELECT * FROM old_issues,borrowers --