Commit 8e71bd07 authored by Andreas Brandl's avatar Andreas Brandl

Maximum page size to 100 for API keyset pagination

This aligns with offset pagination, where we also allow up to 100
records max.
parent 88d33022
...@@ -5,9 +5,12 @@ module Gitlab ...@@ -5,9 +5,12 @@ module Gitlab
module Keyset module Keyset
# A Page models the pagination information for a particular page of the collection # A Page models the pagination information for a particular page of the collection
class Page class Page
# Default and maximum size of records for a page # Default number of records for a page
DEFAULT_PAGE_SIZE = 20 DEFAULT_PAGE_SIZE = 20
# Maximum number of records for a page
MAXIMUM_PAGE_SIZE = 100
attr_accessor :lower_bounds, :end_reached attr_accessor :lower_bounds, :end_reached
attr_reader :order_by attr_reader :order_by
...@@ -22,7 +25,7 @@ module Gitlab ...@@ -22,7 +25,7 @@ module Gitlab
def per_page def per_page
return DEFAULT_PAGE_SIZE if @per_page <= 0 return DEFAULT_PAGE_SIZE if @per_page <= 0
[@per_page, DEFAULT_PAGE_SIZE].min [@per_page, MAXIMUM_PAGE_SIZE].min
end end
# Determine whether this page indicates the end of the collection # Determine whether this page indicates the end of the collection
......
...@@ -4,10 +4,10 @@ require 'spec_helper' ...@@ -4,10 +4,10 @@ require 'spec_helper'
describe Gitlab::Pagination::Keyset::Page do describe Gitlab::Pagination::Keyset::Page do
describe '#per_page' do describe '#per_page' do
it 'limits to a maximum of 20 records per page' do it 'limits to a maximum of 100 records per page' do
per_page = described_class.new(per_page: 21).per_page per_page = described_class.new(per_page: 101).per_page
expect(per_page).to eq(described_class::DEFAULT_PAGE_SIZE) expect(per_page).to eq(described_class::MAXIMUM_PAGE_SIZE)
end end
it 'uses default value when given 0' do it 'uses default value when given 0' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment