Bugzilla – Attachment 120299 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]
Cache Koha::Library object in Branches template plugin
0001-Bug-26587-Cache-library-in-Koha-Template-Plugins-Bra.patch (text/plain), 2.02 KB, created by
Björn Nylén
on 2021-04-29 09:48:08 UTC
(
hide
)
Description:
Cache Koha::Library object in Branches template plugin
Filename:
MIME Type:
Creator:
Björn Nylén
Created:
2021-04-29 09:48:08 UTC
Size:
2.02 KB
patch
obsolete
>From 31bf2c2f46031c21fd94985f5dcd3ba258d5b1d5 Mon Sep 17 00:00:00 2001 >From: =?UTF-8?q?Bj=C3=B6rn=20Nyl=C3=A9n?= <bjorn.nylen@ub.lu.se> >Date: Thu, 29 Apr 2021 10:45:35 +0200 >Subject: [PATCH 1/2] Bug 26587: Cache library in > Koha/Template/Plugins/Branches.pm to improve performance > >This patch caches the Koha::Library object in a hashmap in Branches plugin (GetName, GetURL) >to avoid multiple database lookups. > >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 >--- > Koha/Template/Plugin/Branches.pm | 17 ++++++++++------- > 1 file changed, 10 insertions(+), 7 deletions(-) > >diff --git a/Koha/Template/Plugin/Branches.pm b/Koha/Template/Plugin/Branches.pm >index 92c83be68c..1bb239a63e 100644 >--- a/Koha/Template/Plugin/Branches.pm >+++ b/Koha/Template/Plugin/Branches.pm >@@ -30,8 +30,11 @@ use Koha::Libraries; > sub GetName { > my ( $self, $branchcode ) = @_; > >- my $l = Koha::Libraries->find($branchcode); >- return $l ? $l->branchname : q{}; >+ unless (exists $self->{branches}->{$branchcode} ){ >+ my $l = Koha::Libraries->find($branchcode); >+ $self->{branches}->{$branchcode} = $l if $l; >+ } >+ return $self->{branches}->{$branchcode}->branchname ? $self->{branchname}->{$branchcode} : q{}; > } > > sub GetLoggedInBranchcode { >@@ -49,11 +52,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->{branches}->{$branchcode} ){ >+ my $l = Koha::Libraries->find($branchcode); >+ $self->{branches}->{$branchcode} = $l if $l; >+ } >+ return $self->{branches}->{$branchcode}->branchurl ? $self->{branchname}->{$branchcode} : q{}; > } > > sub all { >-- >2.25.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