Bug 11051: remove unneccessary SQL queries in GetBranches
authorRobin Sheat <robin@catalyst.net.nz>
Tue, 15 Oct 2013 02:01:31 +0000 (15:01 +1300)
committerGalen Charlton <gmc@esilibrary.com>
Fri, 10 Jan 2014 16:02:39 +0000 (16:02 +0000)
commitfb0e7661048747c03304d3a71b1a9aa838c673ae
tree643ba90eed0b16cd4850a1d3a7568aaaf209ca9f
parent15953702bce6dcba94d351655fb42c29edd5789d
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 'Library 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>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
C4/Branch.pm