Bug 17249: Remove GetKohaAuthorisedValuesFromField - (follow-up) inventory
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 5 Sep 2016 15:12:56 +0000 (16:12 +0100)
committerKyle M Hall <kyle@bywatersolutions.com>
Fri, 21 Oct 2016 15:13:57 +0000 (15:13 +0000)
Before this patch set, the tests in
t/db_dependent/Items/GetItemsForInventory.t were executed in 4s. But
with the previous patch, it was in 45sec(!)
To make sure decrease this execution time to what it was before, this
patch introduces a local to avoid the same query to be executed several
times.

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
t/db_dependent/Items/GetItemsForInventory.t

index 32ea963..dfb2175 100755 (executable)
@@ -137,6 +137,7 @@ sub OldWay {
     $sth->execute( @bind_params );
     my ($iTotalRecords) = $sth->fetchrow_array();
 
+    my $marc_field_mapping;
     foreach my $row (@$tmpresults) {
 
         # Auth values
@@ -145,9 +146,14 @@ sub OldWay {
             my ($f, $sf) = C4::Biblio::GetMarcFromKohaField("items.$field", $row->{'frameworkcode'});
             if (defined($f) and defined($sf)) {
                 # We replace the code with it's description
-                my $av = Koha::AuthorisedValues->search_by_marc_field({ frameworkcode => $row->{frameworkcode}, tagfield => $f, tagsubfield => $sf, });
-                $av = $av->count ? $av->unblessed : [];
-                my $authvals = { map { ( $_->{authorised_value} => $_->{lib} ) } @$av };
+                my $avs;
+                if ( exists $marc_field_mapping->{$row->{frameworkcode}}{$f}{$sf} ) {
+                    $avs = $marc_field_mapping->{$row->{frameworkcode}}{$f}{$sf};
+                } else {
+                    $avs = Koha::AuthorisedValues->search_by_marc_field({ frameworkcode => $row->{frameworkcode}, tagfield => $f, tagsubfield => $sf, });
+                    $marc_field_mapping->{$row->{frameworkcode}}{$f}{$sf} = $avs->unblessed;
+                }
+                my $authvals = { map { $_->{authorised_value} => $_->{lib} } @{ $marc_field_mapping->{$row->{frameworkcode}}{$f}{$sf} } };
                 $row->{$field} = $authvals->{$row->{$field}} if defined $authvals && defined $row->{$field} && defined $authvals->{$row->{$field}};
             }
         }