From 158ee8cbadccd5a9547624b1561bbc64b61438cb Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 18 Feb 2022 14:25:41 +0000 Subject: [PATCH] Bug 30133: Avoid calling c->objects->search twice Calling this twice sets double pagination headers, which messes up the page for the requests and retrieves on ly the end of the list This patch simply avoids a doulbe call TO DO: must implement same for Biblio->pickup_locations and cover with tests --- Koha/REST/V1/Items.pm | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Koha/REST/V1/Items.pm b/Koha/REST/V1/Items.pm index 1887bce514..b0e7aaa6ff 100644 --- a/Koha/REST/V1/Items.pm +++ b/Koha/REST/V1/Items.pm @@ -115,19 +115,21 @@ sub pickup_locations { my $ps_set = $item->pickup_locations( { patron => $patron } ); - my $pickup_locations = $c->objects->search( $ps_set ); my @response = (); - if ( C4::Context->preference('AllowHoldPolicyOverride') ) { my $libraries_rs = Koha::Libraries->search( { pickup_location => 1 } ); my $libraries = $c->objects->search($libraries_rs); + return $c->render( + status => 200, + openapi => $libraries + ); @response = map { my $library = $_; $library->{needs_override} = ( any { $_->{library_id} eq $library->{library_id} } - @{$pickup_locations} + @{$ps_set} ) ? Mojo::JSON->false : Mojo::JSON->true; @@ -140,6 +142,8 @@ sub pickup_locations { ); } + my $pickup_locations = $c->objects->search( $ps_set ); + @response = map { $_->{needs_override} = Mojo::JSON->false; $_; } @{$pickup_locations}; return $c->render( -- 2.30.2