From 9ea296c31c9f7983c758bf93e6247bfcd0790643 Mon Sep 17 00:00:00 2001 From: Mark Tompsett Date: Fri, 24 Apr 2015 00:40:46 -0400 Subject: [PATCH] Bug 14057 - A Rough Start This patch is a rough start. I believe it runs exponentially faster, but its equality to the previous version needs to be tested before I clean it up to acceptable standards. --- C4/Items.pm | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index f443d38..6021c85 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -1120,16 +1120,20 @@ sub GetItemsForInventory { $sth->execute( @bind_params ); my ($iTotalRecords) = $sth->fetchrow_array(); + my $query_mapping = "select TA.kohafield,TA.authorised_value AS category,TA.frameworkcode,TB.authorised_value,IF(TB.lib_opac>'',TB.lib_opac,TB.lib) AS OPAC,TB.lib AS Intranet,TB.lib_opac from marc_subfield_structure as TA JOIN authorised_values as TB ON TA.authorised_value=TB.category where TA.kohafield>'' and TA.authorised_value>''"; + $sth = $dbh->prepare($query_mapping); + $sth->execute(); + my $avmapping; + while (my $row = $sth->fetchrow_hashref) { + $avmapping->{$row->{kohafield}}->{$row->{frameworkcode}}->{$row->{authorised_value}} = $row->{OPAC}; + } + foreach my $row (@$tmpresults) { # Auth values foreach (keys %$row) { - # If the koha field is mapped to a marc field - my ($f, $sf) = GetMarcFromKohaField("items.$_", $row->{'frameworkcode'}); - if ($f and $sf) { - # We replace the code with it's description - my $authvals = C4::Koha::GetKohaAuthorisedValuesFromField($f, $sf, $row->{'frameworkcode'}); - $row->{$_} = $authvals->{$row->{$_}} if defined $authvals->{$row->{$_}}; + if (defined($avmapping->{"items.$_"}->{$row->{'frameworkcode'}}->{$row->{$_}})) { + $row->{$_} = $avmapping->{"items.$_"}->{$row->{'frameworkcode'}}->{$row->{$_}}; } } push @results, $row; -- 1.9.1