diff options
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 |