From 56d533a90d95885ff5061bf872fa645c0d9c0983 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 22 Jul 2022 11:07:52 +0000 Subject: [PATCH] Bug 31216: Make one call to fetch AVs before substituting This patch copies logic from GetItemsForInventory as it proves much faster at updating values Probably this should be a subroutine? BUt we have cachign patches in the works too (bug 30920) Additionally - it looks like current inventory code looks for framework from items, but I am not sure we fetch it anywhere --- tools/inventory.pl | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/tools/inventory.pl b/tools/inventory.pl index 6fe7e79014..849a3e6ea6 100755 --- a/tools/inventory.pl +++ b/tools/inventory.pl @@ -296,6 +296,18 @@ if( @scanned_items ) { } + my @avs = Koha::AuthorisedValues->search( + { 'marc_subfield_structures.kohafield' => { '>' => '' }, + 'me.authorised_value' => { '>' => '' }, + }, + { join => { category => 'marc_subfield_structures' }, + distinct => ['marc_subfield_structures.kohafield, me.category, frameworkcode, me.authorised_value'], + '+select' => [ 'marc_subfield_structures.kohafield', 'marc_subfield_structures.frameworkcode', 'me.authorised_value', 'me.lib' ], + '+as' => [ 'kohafield', 'frameworkcode', 'authorised_value', 'lib' ], + } + )->as_list; + my $avmapping = { map { $_->get_column('kohafield') . ',' . $_->get_column('frameworkcode') . ',' . $_->get_column('authorised_value') => $_->get_column('lib') } @avs }; + # Report scanned items that are on the wrong place, or have a wrong notforloan # status, or are still checked out. for ( my $i = 0; $i < @scanned_items; $i++ ) { @@ -306,14 +318,17 @@ for ( my $i = 0; $i < @scanned_items; $i++ ) { my $fc = $item->{'frameworkcode'} || ''; # 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}; + foreach (keys %$item) { + if ( + defined( + $avmapping->{ "items.$_," . $fc . "," . ( $item->{$_} // q{} ) } + ) + ) { + $item->{$_} = $avmapping->{"items.$_,".$fc.",".$item->{$_}}; } } + # If we have scanned items with a non-matching notforloan value if( none { $item->{'notforloancode'} eq $_ } @notforloans ) { $item->{problems}->{changestatus} = 1; -- 2.30.2