Do full page counts on small index pages.

Normally we skip doing page counts on index pages when there aren't any
search filters. This is on the assumption that most index pages have
more than 1000 pages (20,000 results), so it's not worth counting them
exactly. This isn't always true, so here we turn on full counts on
certain index pages known to be small.
This commit is contained in:
evazion
2019-10-28 15:06:02 -05:00
parent fd4a9d4d30
commit 6424a4de74
14 changed files with 16 additions and 16 deletions

View File

@@ -12,7 +12,7 @@ class BansController < ApplicationController
end
def index
@bans = Ban.paginated_search(params)
@bans = Ban.paginated_search(params, count_pages: true)
respond_with(@bans) do |fmt|
fmt.html { @bans = @bans.includes(:user, :banner) }
end

View File

@@ -42,7 +42,7 @@ class BulkUpdateRequestsController < ApplicationController
end
def index
@bulk_update_requests = BulkUpdateRequest.includes(:user, :approver, :forum_topic, forum_post: [:votes]).paginated_search(params)
@bulk_update_requests = BulkUpdateRequest.includes(:user, :approver, :forum_topic, forum_post: [:votes]).paginated_search(params, count_pages: true)
respond_with(@bulk_update_requests)
end

View File

@@ -5,7 +5,7 @@ class CommentVotesController < ApplicationController
rescue_with CommentVote::Error, ActiveRecord::RecordInvalid, status: 422
def index
@comment_votes = CommentVote.includes(:user, comment: [:creator, :post]).paginated_search(params)
@comment_votes = CommentVote.includes(:user, comment: [:creator, :post]).paginated_search(params, count_pages: true)
respond_with(@comment_votes)
end

View File

@@ -19,7 +19,7 @@ class DmailsController < ApplicationController
if params[:folder] && params[:set_default_folder]
cookies.permanent[:dmail_folder] = params[:folder]
end
@dmails = Dmail.active.visible.paginated_search(params)
@dmails = Dmail.active.visible.paginated_search(params, count_pages: true)
respond_with(@dmails)
end

View File

@@ -3,7 +3,7 @@ class ForumPostVotesController < ApplicationController
before_action :member_only, only: [:create, :destroy]
def index
@forum_post_votes = ForumPostVote.includes(creator: [], forum_post: [:topic]).paginated_search(params)
@forum_post_votes = ForumPostVote.includes(creator: [], forum_post: [:topic]).paginated_search(params, count_pages: true)
respond_with(@forum_post_votes)
end

View File

@@ -12,7 +12,7 @@ class IpBansController < ApplicationController
end
def index
@ip_bans = IpBan.includes(:creator).paginated_search(params)
@ip_bans = IpBan.includes(:creator).paginated_search(params, count_pages: true)
respond_with(@ip_bans)
end

View File

@@ -17,7 +17,7 @@ class PoolsController < ApplicationController
end
def index
@pools = Pool.includes(:creator).paginated_search(params)
@pools = Pool.includes(:creator).paginated_search(params, count_pages: true)
respond_with(@pools)
end

View File

@@ -5,7 +5,7 @@ class PostVotesController < ApplicationController
rescue_with PostVote::Error, status: 422
def index
@post_votes = PostVote.includes(:user, post: [:uploader]).paginated_search(params)
@post_votes = PostVote.includes(:user, post: [:uploader]).paginated_search(params, count_pages: true)
respond_with(@post_votes)
end

View File

@@ -1,8 +1,8 @@
class SavedSearchesController < ApplicationController
respond_to :html, :xml, :json, :js
def index
@saved_searches = saved_searches.paginated_search(params)
@saved_searches = saved_searches.paginated_search(params, count_pages: true)
respond_with(@saved_searches)
end

View File

@@ -22,7 +22,7 @@ class TagAliasesController < ApplicationController
end
def index
@tag_aliases = TagAlias.includes(:antecedent_tag, :consequent_tag, :approver).paginated_search(params)
@tag_aliases = TagAlias.includes(:antecedent_tag, :consequent_tag, :approver).paginated_search(params, count_pages: true)
respond_with(@tag_aliases)
end

View File

@@ -22,7 +22,7 @@ class TagImplicationsController < ApplicationController
end
def index
@tag_implications = TagImplication.includes(:antecedent_tag, :consequent_tag, :approver).paginated_search(params)
@tag_implications = TagImplication.includes(:antecedent_tag, :consequent_tag, :approver).paginated_search(params, count_pages: true)
respond_with(@tag_implications)
end

View File

@@ -24,7 +24,7 @@ class UploadsController < ApplicationController
end
def index
@uploads = Upload.paginated_search(params).includes(:post, :uploader)
@uploads = Upload.paginated_search(params, count_pages: true).includes(:post, :uploader)
respond_with(@uploads)
end

View File

@@ -20,7 +20,7 @@ class UserFeedbacksController < ApplicationController
end
def index
@user_feedbacks = UserFeedback.visible.paginated_search(params)
@user_feedbacks = UserFeedback.visible.paginated_search(params, count_pages: true)
respond_with(@user_feedbacks)
end

View File

@@ -7,9 +7,9 @@ class ApplicationRecord < ActiveRecord::Base
extending(PaginationExtension).paginate(*options)
end
def paginated_search(params)
def paginated_search(params, count_pages: params[:search].present?)
search_params = params.fetch(:search, {}).permit!
search(search_params).paginate(params[:page], limit: params[:limit], search_count: params[:search])
search(search_params).paginate(params[:page], limit: params[:limit], search_count: count_pages)
end
end
end