Skip to content

Commit

Permalink
Stop paging if page has less results than previous page
Browse files Browse the repository at this point in the history
  • Loading branch information
mansam committed Jan 29, 2018
1 parent 02631e1 commit 0432002
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ def list
all_objects = objects_on_page = call_list_method(@collection_type, @options, @method)

while more_pages?(objects_on_page)
last_page_count = objects_on_page.length
objects_on_page = call_list_method(@collection_type,
@options,
@method,
:marker => marker(objects_on_page),
:limit => @service.default_pagination_limit)
break if pagination_break?(all_objects, objects_on_page)
all_objects.concat(objects_on_page)
# Break after adding this page if it contained less elements than the previous page.
# having less elements should indicate that this is the last page in the set.
# This is a sanity test to prevent timing-related looping or repetition
break if objects_on_page.length < last_page_count
end

all_objects
Expand Down

0 comments on commit 0432002

Please sign in to comment.