Bugzilla – Attachment 24117 Details for
Bug 11051
Performance of opac-search - GetMarcStructure cache
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
[PASSED QA]Bug 11051 - remove unneccessary SQL queries in GetBranches
Bug-11051---remove-unneccessary-SQL-queries-in-Get.patch (text/plain), 4.20 KB, created by
Jonathan Druart
on 2014-01-10 12:11:12 UTC
(
hide
)
Description:
[PASSED QA]Bug 11051 - remove unneccessary SQL queries in GetBranches
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2014-01-10 12:11:12 UTC
Size:
4.20 KB
patch
obsolete
>From b4f6366a01def771f0b58cbe597b23018f1ac4e0 Mon Sep 17 00:00:00 2001 >From: Robin Sheat <robin@catalyst.net.nz> >Date: Tue, 15 Oct 2013 15:01:31 +1300 >Subject: [PATCH] Bug 11051 - remove unneccessary SQL queries in GetBranches > >The way GetBranches was written, it will issue one query to get all >branches, and then one query per branch for the branch relations. >This patch pre-fetches the relations table (as we need it all anyway) >and so makes the whole process happen in two queries, rather than take >1+N, where N is the number of branches. > >This might not seem like much, but when you do a search, GetBranches is >called once for each result, so 25. And you might have 10 branches. This >causes 275 database requests when you could get away with 50. > >From profiling, when you run a search, this is the thing that calls >DBI::st::execute the most. Refer: >http://debian.koha-community.org/~robin/opac-search/usr-share-koha-lib-C4-Branch-pm-146-line.html#125 > >Test Plan: >* Have a database with branches and relationships between the branches. > (these are 'Lubrary groups' in the UI. >* Make sure the relationships show up correctly after applying the > patch. > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> > >Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com> >--- > C4/Branch.pm | 43 ++++++++++++++++++------------------------- > 1 file changed, 18 insertions(+), 25 deletions(-) > >diff --git a/C4/Branch.pm b/C4/Branch.pm >index 7513cdd..83d2010 100644 >--- a/C4/Branch.pm >+++ b/C4/Branch.pm >@@ -70,8 +70,7 @@ The functions in this module deal with branches. > $branches = &GetBranches(); > > Returns informations about ALL branches, IndependentBranches Insensitive. >-GetBranchInfo() returns the same information without the problems of this function >-(namespace collision, mainly). >+GetBranchInfo() returns the same information. > > Create a branch selector with the following code. > >@@ -106,38 +105,32 @@ Create a branch selector with the following code. > =cut > > sub GetBranches { >- my ($onlymine)=@_; >+ my ($onlymine) = @_; >+ > # returns a reference to a hash of references to ALL branches... > my %branches; > my $dbh = C4::Context->dbh; > my $sth; >- my $query="SELECT * FROM branches"; >+ my $query = "SELECT * FROM branches"; > my @bind_parameters; >- if ($onlymine && C4::Context->userenv && C4::Context->userenv->{branch}){ >- $query .= ' WHERE branchcode = ? '; >- push @bind_parameters, C4::Context->userenv->{branch}; >+ if ( $onlymine && C4::Context->userenv && C4::Context->userenv->{branch} ) { >+ $query .= ' WHERE branchcode = ? '; >+ push @bind_parameters, C4::Context->userenv->{branch}; > } >- $query.=" ORDER BY branchname"; >+ $query .= " ORDER BY branchname"; > $sth = $dbh->prepare($query); >- $sth->execute( @bind_parameters ); >- >- my $nsth = $dbh->prepare( >- "SELECT categorycode FROM branchrelations WHERE branchcode = ?" >- ); # prepare once, outside while loop >+ $sth->execute(@bind_parameters); >+ >+ my $relations_sth = >+ $dbh->prepare("SELECT branchcode,categorycode FROM branchrelations"); >+ $relations_sth->execute(); >+ my %relations; >+ while ( my $rel = $relations_sth->fetchrow_hashref ) { >+ push @{ $relations{ $rel->{branchcode} } }, $rel->{categorycode}; >+ } > > while ( my $branch = $sth->fetchrow_hashref ) { >- $nsth->execute( $branch->{'branchcode'} ); >- while ( my ($cat) = $nsth->fetchrow_array ) { >- # FIXME - This seems wrong. It ought to be >- # $branch->{categorycodes}{$cat} = 1; >- # otherwise, there's a namespace collision if there's a >- # category with the same name as a field in the 'branches' >- # table (i.e., don't create a category called "issuing"). >- # In addition, the current structure doesn't really allow >- # you to list the categories that a branch belongs to: >- # you'd have to list keys %$branch, and remove those keys >- # that aren't fields in the "branches" table. >- # $branch->{$cat} = 1; >+ foreach my $cat ( @{ $relations{ $branch->{branchcode} } } ) { > $branch->{category}{$cat} = 1; > } > $branches{ $branch->{'branchcode'} } = $branch; >-- >1.7.10.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 11051
:
21988
|
21989
|
21990
|
22404
|
22405
|
22406
|
24117