Bugzilla – Attachment 38525 Details for
Bug 14057
Inventory is painfully slow
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 14057 - A Rough Start
Bug-14057---A-Rough-Start.patch (text/plain), 7.10 KB, created by
Mark Tompsett
on 2015-04-27 05:30:40 UTC
(
hide
)
Description:
Bug 14057 - A Rough Start
Filename:
MIME Type:
Creator:
Mark Tompsett
Created:
2015-04-27 05:30:40 UTC
Size:
7.10 KB
patch
obsolete
>From 561efbc903dc06eb9251aa455479de981b45c07a Mon Sep 17 00:00:00 2001 >From: Mark Tompsett <mtompset@hotmail.com> >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. > >Nested hashes of hashes was being a debugging nightmare. > >Moved the SQL select to C4::Koha. > >Changed the GetItemsForInventory to have a hashref parameter. >Added interface, in case there is a need for 'opac' vs. 'staff'. >--- > C4/Items.pm | 40 ++++++++++++++++++++++++++++++++-------- > C4/Koha.pm | 44 ++++++++++++++++++++++++++++++++++++++++++++ > tools/inventory.pl | 30 ++++++++++++++++++++++++++++-- > 3 files changed, 104 insertions(+), 10 deletions(-) > >diff --git a/C4/Items.pm b/C4/Items.pm >index 11ff4ca..35a373b 100644 >--- a/C4/Items.pm >+++ b/C4/Items.pm >@@ -1024,7 +1024,20 @@ sub GetLostItems { > > =head2 GetItemsForInventory > >-($itemlist, $iTotalRecords) = GetItemsForInventory($minlocation, $maxlocation, $location, $itemtype, $ignoreissued, $datelastseen, $branchcode, $offset, $size, $statushash); >+($itemlist, $iTotalRecords) = GetItemsForInventory( { >+ minlocation => $minlocation, >+ maxlocation => $maxlocation, >+ location => $location, >+ itemtype => $itemtype, >+ ignoreissued => $ignoreissued, >+ datelastseen => $datelastseen, >+ branchcode => $branchcode, >+ branch => $branch, >+ offset => $offset, >+ size => $size, >+ stautshash => $statushash >+ interface => $interface, >+} ); > > Retrieve a list of title/authors/barcode/callnumber, for biblio inventory. > >@@ -1042,7 +1055,19 @@ $iTotalRecords is the number of rows that would have been returned without the $ > =cut > > sub GetItemsForInventory { >- my ( $minlocation, $maxlocation,$location, $itemtype, $ignoreissued, $datelastseen, $branchcode, $branch, $offset, $size, $statushash ) = @_; >+ my ( $parameters ) = @_; >+ my $minlocation = $parameters->{'minlocation'} // ''; >+ my $maxlocation = $parameters->{'maxlocation'} // ''; >+ my $location = $parameters->{'location'} // ''; >+ my $itemtype = $parameters->{'itemtype'} // ''; >+ my $ignoreissued = $parameters->{'ignoreissued'} // ''; >+ my $datelastseen = $parameters->{'datelastseen'} // ''; >+ my $branchcode = $parameters->{'branchcode'} // ''; >+ my $branch = $parameters->{'branch'} // ''; >+ my $offset = $parameters->{'offset'} // ''; >+ my $size = $parameters->{'size'} // ''; >+ my $statushash = $parameters->{'statushash'} // ''; >+ > my $dbh = C4::Context->dbh; > my ( @bind_params, @where_strings ); > >@@ -1121,16 +1146,15 @@ sub GetItemsForInventory { > $sth->execute( @bind_params ); > my ($iTotalRecords) = $sth->fetchrow_array(); > >+ my $avmapping = C4::Koha::GetKohaAuthorisedValuesMapping( { >+ interface => 'unknown' >+ } ); > 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; >diff --git a/C4/Koha.pm b/C4/Koha.pm >index 23fbfee..c0769a3 100644 >--- a/C4/Koha.pm >+++ b/C4/Koha.pm >@@ -1327,6 +1327,50 @@ sub GetKohaAuthorisedValuesFromField { > } > } > >+=head2 GetKohaAuthorisedValuesMapping >+ >+Takes a hash as a parameter. The interface key indicates the >+description to use in the mapping. >+ >+Returns hashref of: >+ "{kohafield},{frameworkcode},{authorised_value}" => "{description}" >+for all the kohafields, frameworkcodes, and authorised values. >+ >+Returns undef if nothing is found. >+ >+=cut >+ >+sub GetKohaAuthorisedValuesMapping { >+ my ($parameter) = @_; >+ my $interface = $parameter->{'interface'} // ''; >+ >+ my $query_mapping = q{ >+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>''; >+ }; >+ my $dbh = C4::Context->dbh; >+ my $sth = $dbh->prepare($query_mapping); >+ $sth->execute(); >+ my $avmapping; >+ if ($interface eq 'opac') { >+ while (my $row = $sth->fetchrow_hashref) { >+ $avmapping->{$row->{kohafield}.",".$row->{frameworkcode}.",".$row->{authorised_value}} = $row->{OPAC}; >+ } >+ } >+ else { >+ while (my $row = $sth->fetchrow_hashref) { >+ $avmapping->{$row->{kohafield}.",".$row->{frameworkcode}.",".$row->{authorised_value}} = $row->{Intranet}; >+ } >+ } >+ return $avmapping; >+} >+ > =head2 xml_escape > > my $escaped_string = C4::Koha::xml_escape($string); >diff --git a/tools/inventory.pl b/tools/inventory.pl >index d463d19..015d0be 100755 >--- a/tools/inventory.pl >+++ b/tools/inventory.pl >@@ -234,10 +234,36 @@ if ( $markseen or $op ) { > > # We use datelastseen only when comparing the results to the barcode file. > my $paramdatelastseen = ($compareinv2barcd) ? $datelastseen : ''; >- ($inventorylist, $totalrecords) = GetItemsForInventory($minlocation, $maxlocation, $location, $itemtype, $ignoreissued, $paramdatelastseen, $branchcode, $branch, 0, undef, $staton); >+ ($inventorylist, $totalrecords) = GetItemsForInventory( { >+ minlocation => $minlocation, >+ maxlocation => $maxlocation, >+ location => $location, >+ itemtype => $itemtype, >+ ignoreissued => $ignoreissued, >+ datelastseen => $paramdatelastseen, >+ branchcode => $branchcode, >+ branch => $branch, >+ offset => 0, >+ size => undef, >+ statushash => $staton, >+ interface => 'staff', >+ } ); > > # For the items that may be marked as "wrong place", we only check the location (callnumbers, location and branch) >- ($wrongplacelist, $totalrecords) = GetItemsForInventory($minlocation, $maxlocation, $location, undef, undef, undef, $branchcode, $branch, 0, undef, undef); >+ ($wrongplacelist, $totalrecords) = GetItemsForInventory( { >+ minlocation => $minlocation, >+ maxlocation => $maxlocation, >+ location => $location, >+ itemtype => undef, >+ ignoreissued => undef, >+ datelastseen => undef, >+ branchcode => $branchcode, >+ branch => $branch, >+ offset => 0, >+ size => undef, >+ statushash => undef, >+ interface => 'staff', >+ } ); > > } > >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 14057
:
38472
|
38482
|
38483
|
38500
|
38506
|
38507
|
38525
|
38621
|
38622
|
38636
|
38733