Bugzilla – Attachment 124655 Details for
Bug 28436
Cache relatively static info that is used often and on many pages (instead of fetching from DB)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 28436: Add local cache to Template Plugins for branches and itemtypes
Bug-28436-Add-local-cache-to-Template-Plugins-for-.patch (text/plain), 2.43 KB, created by
Nick Clemens (kidclamp)
on 2021-09-08 12:40:28 UTC
(
hide
)
Description:
Bug 28436: Add local cache to Template Plugins for branches and itemtypes
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2021-09-08 12:40:28 UTC
Size:
2.43 KB
patch
obsolete
>From bd88453971d2f0b2c97b7ba1b728ab5a8922f1d2 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Wed, 8 Sep 2021 12:37:38 +0000 >Subject: [PATCH] Bug 28436: Add local cache to Template Plugins for branches > and itemtypes > >This patch simply stores the branches an itemtypes in a hash for lookup. >This improves efficiency on pages where we are loading many items > >To test: >1 - Add ~1000 items to a record >2 - Note load time >3 - Apply patch >4 - Reload and note faster load >5 - Edit a branchname/itemtype description >6 - Reload page >7 - Confirm the updated name is reflected in display >--- > Koha/Template/Plugin/Branches.pm | 7 +++++-- > Koha/Template/Plugin/ItemTypes.pm | 10 +++++++--- > 2 files changed, 12 insertions(+), 5 deletions(-) > >diff --git a/Koha/Template/Plugin/Branches.pm b/Koha/Template/Plugin/Branches.pm >index 92c83be68c..a19efeaca5 100644 >--- a/Koha/Template/Plugin/Branches.pm >+++ b/Koha/Template/Plugin/Branches.pm >@@ -27,11 +27,14 @@ use C4::Koha; > use C4::Context; > use Koha::Libraries; > >+our %branches; >+ > sub GetName { > my ( $self, $branchcode ) = @_; > >- my $l = Koha::Libraries->find($branchcode); >- return $l ? $l->branchname : q{}; >+ %branches = map { $_->{branchcode} => $_ } @{Koha::Libraries->search()->unblessed} unless %branches; >+ my $l = $branches{$branchcode}; >+ return $l ? $l->{branchname} : q{}; > } > > sub GetLoggedInBranchcode { >diff --git a/Koha/Template/Plugin/ItemTypes.pm b/Koha/Template/Plugin/ItemTypes.pm >index 5b3cf1edeb..f0e6ed24c2 100644 >--- a/Koha/Template/Plugin/ItemTypes.pm >+++ b/Koha/Template/Plugin/ItemTypes.pm >@@ -24,13 +24,17 @@ use base qw( Template::Plugin ); > > use Koha::ItemTypes; > >+our %itemtypes; >+ >+ > sub GetDescription { > my ( $self, $itemtypecode, $want_parent ) = @_; >- my $itemtype = Koha::ItemTypes->find( $itemtypecode ); >+ %itemtypes = map { $_->{itemtype} => $_ } @{Koha::ItemTypes->search_with_localization()->unblessed} unless %itemtypes; >+ my $itemtype = $itemtypes{$itemtypecode}; > return q{} unless $itemtype; > my $parent; >- $parent = $itemtype->parent if $want_parent; >- return $parent ? $parent->translated_description . "->" . $itemtype->translated_description : $itemtype->translated_description; >+ $parent = $itemtypes{$itemtype->{parent_type}} if $want_parent; >+ return $parent ? $parent->{translated_description} . "->" . $itemtype->{translated_description} : $itemtype->{translated_description}; > } > > sub Get { >-- >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 28436
:
124655