From 4c76583e6d3079bad51048f62f43c3c433f1e9bd Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Wed, 2 Aug 2017 11:21:58 +0200 Subject: [PATCH] Bug 19023 - inventory tool performance Inventory tool performance seems to be worst since 16.11. I think it is because of authorized values computing changed by Bug 17249. For each subfield of each item, we try to get the authorized value description with Koha::AuthorisedValues->search_by_marc_field. But this method does not use cache like Koha::AuthorisedValues->get_description_by_koha_field. I propose to use Koha::AuthorisedValues->get_description_by_koha_field and also to look for authorized value description only for item fields used in TT : location, notforloan, itemlost, damaged, withdrawn. I have experimented inventory time on 100 items from 5s to 1s. Test plan : - Without patch - Perform inventory with barcode file - Check results and mesure execution time - Apply patch - Reperform inventory with same barcode file - Check results is the same - Compare execution time - Run prove t/db_dependent/Items/GetItemsForInventory.t Signed-off-by: Owen Leonard Signed-off-by: Kyle M Hall Signed-off-by: Jonathan Druart (cherry picked from commit 95f1844e6c46ff51de9f95f99fcdf3369c756fd4) Signed-off-by: Fridolin Somers --- tools/inventory.pl | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/tools/inventory.pl b/tools/inventory.pl index 1ee40a1014..2a26c5605f 100755 --- a/tools/inventory.pl +++ b/tools/inventory.pl @@ -255,20 +255,14 @@ if( @scanned_items ) { # status, or are still checked out. foreach my $item ( @scanned_items ) { $item->{notforloancode} = $item->{notforloan}; # save for later use + my $fc = $item->{'frameworkcode'} || ''; - # Populating with authorised values - foreach my $field ( keys %$item ) { - # If the koha field is mapped to a marc field - my $fc = $item->{'frameworkcode'} || ''; - my ($f, $sf) = GetMarcFromKohaField("items.$field", $fc); - if ($f and $sf) { - # We replace the code with it's description - my $av = Koha::AuthorisedValues->search_by_marc_field({ frameworkcode => $fc, tagfield => $f, tagsubfield => $sf, }); - $av = $av->count ? $av->unblessed : []; - my $authvals = { map { ( $_->{authorised_value} => $_->{lib} ) } @$av }; - if ($authvals and defined $item->{$field} and defined $authvals->{$item->{$field}}) { - $item->{$field} = $authvals->{$item->{$field}}; - } + # Populating with authorised values description + foreach my $field (qw/ location notforloan itemlost damaged withdrawn /) { + my $av = Koha::AuthorisedValues->get_description_by_koha_field( + { frameworkcode => $fc, kohafield => "items.$field", authorised_value => $item->{$field} } ); + if ( $av and defined $item->{$field} and defined $av->{lib} ) { + $item->{$field} = $av->{lib}; } } @@ -356,7 +350,7 @@ if (defined $input->param('CSVexport') && $input->param('CSVexport') eq 'on'){ $csv->combine(@translated_keys); print $csv->string, "\n"; - my @keys = qw / title author barcode itemnumber homebranch location itemcallnumber notforloan lost damaged withdrawn stocknumber /; + my @keys = qw/ title author barcode itemnumber homebranch location itemcallnumber notforloan lost damaged withdrawn stocknumber /; for my $item ( @$loop ) { my @line; for my $key (@keys) { -- 2.39.5