Bugzilla – Attachment 113283 Details for
Bug 26963
Improve Koha::Item::pickup_locations performance
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 26963: Koha::Template::Plugin::Branches::pickup_locations is very inefficient, causing timeouts on records with large numbers of holds/items
Bug-26963-KohaTemplatePluginBranchespickuplocation.patch (text/plain), 3.83 KB, created by
Kyle M Hall
on 2020-11-07 12:45:35 UTC
(
hide
)
Description:
Bug 26963: Koha::Template::Plugin::Branches::pickup_locations is very inefficient, causing timeouts on records with large numbers of holds/items
Filename:
MIME Type:
Creator:
Kyle M Hall
Created:
2020-11-07 12:45:35 UTC
Size:
3.83 KB
patch
obsolete
>From 356f8ac2c91712f6d95abd32d4e2de46ddae899f Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Sat, 7 Nov 2020 07:22:15 -0500 >Subject: [PATCH] Bug 26963: Koha::Template::Plugin::Branches::pickup_locations > is very inefficient, causing timeouts on records with large numbers of > holds/items > >If a record has a large number of holds ( > 50 I'd say ), and a large number of items, checking the pickup locations takes so long the script often times out. We need to find a way to cache the results so we don't have to spend so much time on expensive lookups. > >Test Plan: >1) Create a record with 100 items >2) Create 100 holds that are item level >3) You should start to see slow page loads as you create more holds >4) Apply this patch >5) Restart all the things! >6) Note the hold page now loads faster >7) Subsequent loads should be even faster due to the caching mechanism >--- > Koha/Template/Plugin/Branches.pm | 40 +++++++++++++++++++++++++------- > 1 file changed, 32 insertions(+), 8 deletions(-) > >diff --git a/Koha/Template/Plugin/Branches.pm b/Koha/Template/Plugin/Branches.pm >index 05932dac68..815e5a768b 100644 >--- a/Koha/Template/Plugin/Branches.pm >+++ b/Koha/Template/Plugin/Branches.pm >@@ -25,6 +25,7 @@ use base qw( Template::Plugin ); > > use C4::Koha; > use C4::Context; >+use Koha::Caches; > use Koha::Libraries; > > sub GetName { >@@ -105,6 +106,9 @@ sub pickup_locations { > my $selected = $params->{selected}; > my @libraries; > >+ my $cache = Koha::Caches->get_instance(); >+ my $cache_key; >+ > if(defined $search_params->{item} || defined $search_params->{biblio}) { > my $item = $search_params->{'item'}; > my $biblio = $search_params->{'biblio'}; >@@ -117,22 +121,41 @@ sub pickup_locations { > if ($item) { > $item = Koha::Items->find($item) > unless ref($item) eq 'Koha::Item'; >- @libraries = @{ $item->pickup_locations( { patron => $patron } ) } >- if defined $item; >+ >+ if ( defined $item ) { >+ $cache_key = "I" . $item->homebranch . "-" . $patron->branchcode; >+ my $result = $cache->get_from_cache($cache_key); >+ if ( $result ) { >+ @libraries = @{$result}; >+ } else { >+ @libraries = @{ $item->pickup_locations( { patron => $patron } ) }; >+ @libraries = map { $_->unblessed } @libraries; >+ } >+ } > } > elsif ($biblio) { > $biblio = Koha::Biblios->find($biblio) > unless ref($biblio) eq 'Koha::Biblio'; >- @libraries = @{ $biblio->pickup_locations( { patron => $patron } ) } >- if defined $biblio; >+ >+ if ( defined $biblio ) { >+ $cache_key = "B" . $biblio->id . "-" . $patron->branchcode; >+ my $result = $cache->get_from_cache($cache_key); >+ if ( $result ) { >+ @libraries = @{$result}; >+ } else { >+ @libraries = @{ $biblio->pickup_locations( { patron => $patron } ) }; >+ @libraries = map { $_->unblessed } @libraries; >+ } >+ } > } > } > >- @libraries = Koha::Libraries->search( { pickup_location => 1 }, >- { order_by => ['branchname'] } )->as_list >- unless @libraries; >+ unless ( @libraries ) { >+ @libraries = Koha::Libraries->search( { pickup_location => 1 }, >+ { order_by => ['branchname'] } )->as_list; > >- @libraries = map { $_->unblessed } @libraries; >+ @libraries = map { $_->unblessed } @libraries; >+ } > > for my $l (@libraries) { > if ( defined $selected and $l->{branchcode} eq $selected >@@ -144,6 +167,7 @@ sub pickup_locations { > } > } > >+ $cache->set_in_cache( $cache_key, \@libraries ); > return \@libraries; > } > >-- >2.24.1 (Apple Git-126)
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 26963
:
113282
|
113283
|
113329
|
113330
|
113333
|
113339
|
113340
|
113419
|
113420
|
113422
|
113423
|
113424
|
113425
|
113451
|
113452
|
113453
|
113454
|
113455
|
113480
|
113481
|
113483
|
113498
|
113503
|
113504
|
113505
|
113506
|
113507
|
113508
|
113509
|
113510
|
113511
|
113512
|
113513
|
113514
|
113515
|
113516
|
113517
|
113518
|
113519
|
113520
|
113521
|
113523
|
113524
|
113525
|
113526
|
113527
|
113528
|
113529
|
113530
|
113531
|
113586
|
113729