From 702da2e08f87cb82a0f55a96e4e86fe0ab64c867 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 7 Apr 2023 21:08:30 +0000 Subject: [PATCH] Bug 33447: Add Cache to Biblio->pickup_locations This is going to have the most effect on records with large numbers of items held by the same library, serial records and the like To test: 1 - Add 500 items to a biblio by select myltiple copies on the add item page 2 - Place a hold via the API and note response time, I found ~3-5 seconds 3 - Apply patch 4 - Restart all 5 - Place hold using api again 6 - Note improved response time, less than 1/2 a second in my tests Signed-off-by: emlam Signed-off-by: Marcel de Rooy Signed-off-by: Tomas Cohen Arazi (cherry picked from commit 55dc8573c709493f52bf7a2c87f82900fa926d1a) Signed-off-by: Jacob O'Mara --- Koha/Biblio.pm | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index c74b6ac556..e5cf7ae2c5 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -35,6 +35,7 @@ use Koha::ArticleRequests; use Koha::Biblio::Metadatas; use Koha::Biblio::ItemGroups; use Koha::Biblioitems; +use Koha::Cache::Memory::Lite; use Koha::Checkouts; use Koha::CirculationRules; use Koha::Item::Transfer::Limits; @@ -252,11 +253,17 @@ sub pickup_locations { my $patron = $params->{patron}; + my $memory_cache = Koha::Cache::Memory::Lite->get_instance(); my @pickup_locations; - foreach my $item_of_bib ( $self->items->as_list ) { - push @pickup_locations, - $item_of_bib->pickup_locations( { patron => $patron } ) - ->_resultset->get_column('branchcode')->all; + foreach my $item ( $self->items->as_list ) { + my $cache_key = sprintf "Pickup_locations:%s:%s:%s:%s:%s", + $item->itype,$item->homebranch,$item->holdingbranch,$item->ccode || "",$patron->branchcode||"" ; + my $item_pickup_locations = $memory_cache->get_from_cache( $cache_key ); + unless( $item_pickup_locations ){ + @{ $item_pickup_locations } = $item->pickup_locations( { patron => $patron } )->_resultset->get_column('branchcode')->all; + $memory_cache->set_in_cache( $cache_key, $item_pickup_locations ); + } + push @pickup_locations, @{ $item_pickup_locations } } return Koha::Libraries->search( -- 2.39.5