debian-mirror-gitlab/lib/gitlab/pagination/cursor_based_keyset.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

41 lines
1.2 KiB
Ruby
Raw Normal View History

2021-11-11 11:23:49 +05:30
# frozen_string_literal: true
module Gitlab
module Pagination
module CursorBasedKeyset
SUPPORTED_ORDERING = {
2022-08-13 15:12:31 +05:30
Group => { name: :asc },
AuditEvent => { id: :desc }
2021-11-11 11:23:49 +05:30
}.freeze
2022-08-13 15:12:31 +05:30
# Relation types that are enforced in this list
# enforce the use of keyset pagination, thus erroring out requests
# made with offset pagination above a certain limit.
#
# In many cases this could introduce a breaking change
# so enforcement is optional.
ENFORCED_TYPES = [Group].freeze
2021-11-11 11:23:49 +05:30
def self.available_for_type?(relation)
SUPPORTED_ORDERING.key?(relation.klass)
end
def self.available?(cursor_based_request_context, relation)
available_for_type?(relation) &&
order_satisfied?(relation, cursor_based_request_context)
end
2022-08-13 15:12:31 +05:30
def self.enforced_for_type?(relation)
ENFORCED_TYPES.include?(relation.klass)
end
2021-11-11 11:23:49 +05:30
def self.order_satisfied?(relation, cursor_based_request_context)
order_by_from_request = cursor_based_request_context.order_by
SUPPORTED_ORDERING[relation.klass] == order_by_from_request
end
private_class_method :order_satisfied?
end
end
end