Bugzilla – Attachment 127411 Details for
Bug 26587
Cache libraries in Branches TT plugin to improve performance
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 26587: Cache libraries in Koha/Template/Plugins/Branches.pm to improve performance
Bug-26587-Cache-libraries-in-KohaTemplatePluginsBr.patch (text/plain), 2.49 KB, created by
Joonas Kylmälä
on 2021-11-06 16:01:33 UTC
(
hide
)
Description:
Bug 26587: Cache libraries in Koha/Template/Plugins/Branches.pm to improve performance
Filename:
MIME Type:
Creator:
Joonas Kylmälä
Created:
2021-11-06 16:01:33 UTC
Size:
2.49 KB
patch
obsolete
>From 4a872758c13fe852e670865a0116e8788f12240c Mon Sep 17 00:00:00 2001 >From: =?UTF-8?q?Bj=C3=B6rn=20Nyl=C3=A9n?= <bjorn.nylen@ub.lu.se> >Date: Mon, 3 May 2021 13:13:25 +0200 >Subject: [PATCH] Bug 26587: Cache libraries in > Koha/Template/Plugins/Branches.pm to improve performance >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >This patch caches the Koha::Library object in a hashmap in the Branches object (GetName, GetURL) >to avoid multiple database lookups while looping many items. > >To test: >1. Have a biblio with many items (1000's). >2. View in staff (detail.pl) and opac (opac-detail.pl). Note how long it takes to load. >3. Apply patch. >4. Repeat 2. Note that pages load faster. > >Sponsored-by: Lund University Library >JK: replaced tab indendation with spaces >Signed-off-by: Joonas Kylmälä <joonas.kylmala@iki.fi> >--- > Koha/Template/Plugin/Branches.pm | 27 ++++++++++++++++++++------- > 1 file changed, 20 insertions(+), 7 deletions(-) > >diff --git a/Koha/Template/Plugin/Branches.pm b/Koha/Template/Plugin/Branches.pm >index 92c83be68c..c4f552a71f 100644 >--- a/Koha/Template/Plugin/Branches.pm >+++ b/Koha/Template/Plugin/Branches.pm >@@ -27,11 +27,24 @@ use C4::Koha; > use C4::Context; > use Koha::Libraries; > >+sub new { >+ my ($self) = shift; >+ my (@params) = @_; >+ $self = $self->SUPER::new(@params); >+ #Initialize a cache of libraries for lookups of names,urls etc. >+ $self->{libraries} = {}; >+ >+ return $self; >+} >+ > sub GetName { > my ( $self, $branchcode ) = @_; > >- my $l = Koha::Libraries->find($branchcode); >- return $l ? $l->branchname : q{}; >+ unless (exists $self->{libraries}->{$branchcode} ){ >+ my $l = Koha::Libraries->find($branchcode); >+ $self->{libraries}->{$branchcode} = $l if $l; >+ } >+ return $self->{libraries}->{$branchcode} ? $self->{libraries}->{$branchcode}->branchname : q{}; > } > > sub GetLoggedInBranchcode { >@@ -49,11 +62,11 @@ sub GetLoggedInBranchname { > sub GetURL { > my ( $self, $branchcode ) = @_; > >- my $query = "SELECT branchurl FROM branches WHERE branchcode = ?"; >- my $sth = C4::Context->dbh->prepare($query); >- $sth->execute($branchcode); >- my $b = $sth->fetchrow_hashref(); >- return $b->{branchurl}; >+ unless (exists $self->{libraries}->{$branchcode} ){ >+ my $l = Koha::Libraries->find($branchcode); >+ $self->{libraries}->{$branchcode} = $l if $l; >+ } >+ return $self->{libraries}->{$branchcode} ? $self->{libraries}->{$branchcode}->branchurl : q{}; > } > > sub all { >-- >2.20.1
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 26587
:
120298
|
120299
|
120300
|
120311
|
120401
|
120402
|
127411
|
128446
|
128470
|
128471