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
this also returns all as needing override

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Nick Clemens 2022-02-18 14:25:41 +00:00 committed by Fridolin Somers
parent 60b07917f3
commit 1758b58642

View file

@ -115,9 +115,7 @@ 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 } );
@ -127,7 +125,7 @@ sub pickup_locations {
my $library = $_;
$library->{needs_override} = (
any { $_->{library_id} eq $library->{library_id} }
@{$pickup_locations}
@{$ps_set->as_list}
)
? Mojo::JSON->false
: Mojo::JSON->true;
@ -140,6 +138,8 @@ sub pickup_locations {
);
}
my $pickup_locations = $c->objects->search( $ps_set );
@response = map { $_->{needs_override} = Mojo::JSON->false; $_; } @{$pickup_locations};
return $c->render(