pagination.rb 741 Bytes
Newer Older
1
2
# frozen_string_literal: true

3
4
5
6
module API
  module Helpers
    module Pagination
      def paginate(relation)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
        return Gitlab::Pagination::OffsetPagination.new(self).paginate(relation) unless keyset_pagination_enabled?

        request_context = Gitlab::Pagination::Keyset::RequestContext.new(self)

        unless Gitlab::Pagination::Keyset.available?(request_context, relation)
          return error!('Keyset pagination is not yet available for this type of request', 501)
        end

        Gitlab::Pagination::Keyset.paginate(request_context, relation)
      end

      private

      def keyset_pagination_enabled?
        params[:pagination] == 'keyset' && Feature.enabled?(:api_keyset_pagination)
22
      end
23
24
25
    end
  end
end