From d9619b86a49115db65a1fc9574abb34478134a7f Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 11 Dec 2025 14:24:08 +0000 Subject: [PATCH] Bug 41432: Prefetch items and borrowers for holds To test: 1 - Add a bunch of holds to a record https://github.com/kidclamp/handy-koha-script/blob/main/randhold.pl 2 - Enable profiling: https://wiki.koha-community.org/wiki/Profiling_with_Devel::NYTProf#NYTProf_with_Plack 3 - Browse to the record and load the holds table 4 - View the flame graph for the request like instructions in #2 5 - Note that Koha::Hold->borrower and Koha::Hold->item take a lot of time 6 - Apply patch, restart all 7 - Reload page 8 - Reload flame graph 9 - Note time for fetching borrowers and items is significantly reduced 10 - Sing off! --- reserve/request.pl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/reserve/request.pl b/reserve/request.pl index 41e05088835..fbb94fbed3a 100755 --- a/reserve/request.pl +++ b/reserve/request.pl @@ -683,8 +683,10 @@ if ( ( $findborrower && $borrowernumber_hold || $findclub && $club_hold ) )->unblessed } }; - my @reserves = - Koha::Holds->search( { biblionumber => $biblionumber }, { order_by => 'priority' } )->as_list; + my @reserves = Koha::Holds->search( + { 'me.biblionumber' => $biblionumber }, + { prefetch => [ 'borrowernumber', 'itemnumber' ], order_by => 'priority' } + )->as_list; foreach my $res ( sort { my $a_found = $a->found() || ''; -- 2.39.5