From f8e7061fd47225b396cb95bbd64d9f18f225e516 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 5 Sep 2016 16:12:56 +0100 Subject: [PATCH] [PASSED QA] Bug 17249: Remove GetKohaAuthorisedValuesFromField - (follow-up) inventory 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 Signed-off-by: Martin Renvoize --- t/db_dependent/Items/GetItemsForInventory.t | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/t/db_dependent/Items/GetItemsForInventory.t b/t/db_dependent/Items/GetItemsForInventory.t index 32ea963..dfb2175 100755 --- a/t/db_dependent/Items/GetItemsForInventory.t +++ b/t/db_dependent/Items/GetItemsForInventory.t @@ -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}}; } } -- 2.1.4