Commit 1593c81f authored by Nick Thomas's avatar Nick Thomas

Use pagination without counts when appropriate

parent 517a05c7
......@@ -41,10 +41,13 @@ module IssuableCollections
end
def set_pagination
row_count = finder.row_count
@issuables = @issuables.page(params[:page])
@issuables = per_page_for_relative_position if params[:sort] == 'relative_position'
@issuables = @issuables.without_count if row_count == -1
@issuable_meta_data = Gitlab::IssuableMetadata.new(current_user, @issuables).data
@total_pages = issuable_page_count(@issuables)
@total_pages = page_count_for_relation(@issuables, row_count)
end
# rubocop:enable Gitlab/ModuleWithInstanceVariables
......@@ -58,10 +61,6 @@ module IssuableCollections
end
# rubocop: enable CodeReuse/ActiveRecord
def issuable_page_count(relation)
page_count_for_relation(relation, finder.row_count)
end
def page_count_for_relation(relation, row_count)
limit = relation.limit_value.to_f
......
# frozen_string_literal: true
module PaginationHelper
def paginate_collection(collection, remote: nil)
# total_pages will be inferred from the collection if nil. It is ignored if
# the collection is a Kaminari::PaginatableWithoutCount
def paginate_collection(collection, remote: nil, total_pages: nil)
if collection.is_a?(Kaminari::PaginatableWithoutCount)
paginate_without_count(collection)
elsif collection.respond_to?(:total_pages)
paginate_with_count(collection, remote: remote)
paginate_with_count(collection, remote: remote, total_pages: total_pages)
end
end
......@@ -17,7 +19,7 @@ module PaginationHelper
)
end
def paginate_with_count(collection, remote: nil)
paginate(collection, remote: remote, theme: 'gitlab')
def paginate_with_count(collection, remote: nil, total_pages: nil)
paginate(collection, remote: remote, theme: 'gitlab', total_pages: total_pages)
end
end
......@@ -20,4 +20,4 @@
= render empty_state_path
- if @issues.present?
= paginate @issues, theme: "gitlab", total_pages: @total_pages
= paginate_collection @issues, total_pages: @total_pages
......@@ -5,4 +5,4 @@
= render 'shared/empty_states/merge_requests'
- if @merge_requests.present?
= paginate @merge_requests, theme: "gitlab", total_pages: @total_pages
= paginate_collection @merge_requests, total_pages: @total_pages
......@@ -2,4 +2,4 @@
%ul.content-list.issuable-list
= render partial: 'groups/epics/epic', collection: @epics
= paginate @epics, theme: "gitlab"
= paginate_collection @epics
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment