From 1a7229e54e9f112b43c727e351a13a860c843f21 Mon Sep 17 00:00:00 2001 From: Agustin Moyano Date: Fri, 3 Mar 2023 14:35:45 -0300 Subject: [PATCH] Bug 33080: (follow-up) Move pagination logic out of search_rs --- Koha/REST/Plugin/Objects.pm | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/Koha/REST/Plugin/Objects.pm b/Koha/REST/Plugin/Objects.pm index 462fdf97da..ff56341502 100644 --- a/Koha/REST/Plugin/Objects.pm +++ b/Koha/REST/Plugin/Objects.pm @@ -114,7 +114,22 @@ shouldn't be called twice in it. 'objects.search' => sub { my ( $c, $result_set ) = @_; - return $c->objects->to_api( $c->objects->search_rs($result_set) ); + my $objects = $c->objects->search_rs($result_set); + my $total = $result_set->search->count; + + $c->add_pagination_headers( + { + total => ( + $objects->is_paged + ? $objects->pager->total_entries + : $objects->count + ), + base_total => $total, + params => $args, + } + ); + + return $c->objects->to_api( $objects ); } ); @@ -246,19 +261,6 @@ shouldn't be called twice in it. # Perform search my $objects = $result_set->search( $filtered_params, $attributes ); - my $total = $result_set->search->count; - - $c->add_pagination_headers( - { - total => ( - $objects->is_paged - ? $objects->pager->total_entries - : $objects->count - ), - base_total => $total, - params => $args, - } - ); return $objects; } -- 2.25.1