Bugzilla – Attachment 127520 Details for
Bug 29454
Stash itemtypes in plugin objects to reduce DB calls
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29454: Add local cache to Template Plugins for branches and itemtypes
Bug-29454-Add-local-cache-to-Template-Plugins-for-.patch (text/plain), 2.58 KB, created by
David Nind
on 2021-11-10 23:04:34 UTC
(
hide
)
Description:
Bug 29454: Add local cache to Template Plugins for branches and itemtypes
Filename:
MIME Type:
Creator:
David Nind
Created:
2021-11-10 23:04:34 UTC
Size:
2.58 KB
patch
obsolete
>From 6eabe663157b34df4953bf7cca738d5c2e5b9632 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 29454: 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 > >Signed-off-by: David Nind <david@davidnind.com> >--- > Koha/Template/Plugin/Branches.pm | 13 ++++++++++--- > Koha/Template/Plugin/ItemTypes.pm | 15 ++++++++++++--- > 2 files changed, 22 insertions(+), 6 deletions(-) > >diff --git a/Koha/Template/Plugin/Branches.pm b/Koha/Template/Plugin/Branches.pm >index 92c83be68c..78a95e235a 100644 >--- a/Koha/Template/Plugin/Branches.pm >+++ b/Koha/Template/Plugin/Branches.pm >@@ -27,11 +27,18 @@ use C4::Koha; > use C4::Context; > use Koha::Libraries; > >+our %branches; >+ >+sub new { >+ my ($class, $context, @params) = @_; >+ bless { >+ map { $_->{branchcode} => $_ } @{Koha::Libraries->search()->unblessed} >+ }, $class; >+} >+ > sub GetName { > my ( $self, $branchcode ) = @_; >- >- my $l = Koha::Libraries->find($branchcode); >- return $l ? $l->branchname : q{}; >+ return $self->{$branchcode}->{branchname} // $branchcode; > } > > sub GetLoggedInBranchcode { >diff --git a/Koha/Template/Plugin/ItemTypes.pm b/Koha/Template/Plugin/ItemTypes.pm >index 5b3cf1edeb..6f620ba09e 100644 >--- a/Koha/Template/Plugin/ItemTypes.pm >+++ b/Koha/Template/Plugin/ItemTypes.pm >@@ -24,13 +24,22 @@ use base qw( Template::Plugin ); > > use Koha::ItemTypes; > >+our %itemtypes; >+ >+sub new { >+ my ($class, $context, @params) = @_; >+ bless { >+ map { $_->{itemtype} => $_ } @{Koha::ItemTypes->search_with_localization()->unblessed} >+ }, $class; >+} >+ > sub GetDescription { > my ( $self, $itemtypecode, $want_parent ) = @_; >- my $itemtype = Koha::ItemTypes->find( $itemtypecode ); >+ my $itemtype = $self->{$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 = $self->{$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 29454
:
127515
|
127520
|
128472
|
136077
|
136078
|
136090
|
136091
|
136149
|
136150
|
136151