Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'config/initializers/active_record_keyset_pagination.rb')
-rw-r--r--config/initializers/active_record_keyset_pagination.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/config/initializers/active_record_keyset_pagination.rb b/config/initializers/active_record_keyset_pagination.rb
new file mode 100644
index 00000000000..f8c2ada5255
--- /dev/null
+++ b/config/initializers/active_record_keyset_pagination.rb
@@ -0,0 +1,12 @@
+# frozen_string_literal: true
+
+module PaginatorExtension
+ # This method loads the records for the requested page and returns a keyset paginator object.
+ def keyset_paginate(cursor: nil, per_page: 20)
+ Gitlab::Pagination::Keyset::Paginator.new(scope: self.dup, cursor: cursor, per_page: per_page)
+ end
+end
+
+ActiveSupport.on_load(:active_record) do
+ ActiveRecord::Relation.include(PaginatorExtension)
+end