diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /lib/gitlab/pagination/gitaly_keyset_pager.rb | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'lib/gitlab/pagination/gitaly_keyset_pager.rb')
-rw-r--r-- | lib/gitlab/pagination/gitaly_keyset_pager.rb | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/lib/gitlab/pagination/gitaly_keyset_pager.rb b/lib/gitlab/pagination/gitaly_keyset_pager.rb index 651e3d5a807..1350168967e 100644 --- a/lib/gitlab/pagination/gitaly_keyset_pager.rb +++ b/lib/gitlab/pagination/gitaly_keyset_pager.rb @@ -15,6 +15,7 @@ module Gitlab # and supports pagination via gitaly. def paginate(finder) return paginate_via_gitaly(finder) if keyset_pagination_enabled? + return paginate_first_page_via_gitaly(finder) if paginate_first_page? branches = ::Kaminari.paginate_array(finder.execute) Gitlab::Pagination::OffsetPagination @@ -25,7 +26,11 @@ module Gitlab private def keyset_pagination_enabled? - Feature.enabled?(:branch_list_keyset_pagination, project) && params[:pagination] == 'keyset' + Feature.enabled?(:branch_list_keyset_pagination, project, default_enabled: true) && params[:pagination] == 'keyset' + end + + def paginate_first_page? + Feature.enabled?(:branch_list_keyset_pagination, project, default_enabled: true) && (params[:page].blank? || params[:page].to_i == 1) end def paginate_via_gitaly(finder) @@ -34,6 +39,20 @@ module Gitlab end end + # When first page is requested, we paginate the data via Gitaly + # Headers are added to immitate offset pagination, while it is the default option + def paginate_first_page_via_gitaly(finder) + finder.execute(gitaly_pagination: true).tap do |records| + total = project.repository.branch_count + per_page = params[:per_page].presence || Kaminari.config.default_per_page + + Gitlab::Pagination::OffsetHeaderBuilder.new( + request_context: request_context, per_page: per_page, page: 1, next_page: 2, + total: total, total_pages: total / per_page + 1 + ).execute + end + end + def apply_headers(records) if records.count == params[:per_page] Gitlab::Pagination::Keyset::HeaderBuilder |