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:18:54 -05:00
parent fd4a9d4d30
commit 6424a4de74
14 changed files with 16 additions and 16 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ class BansController < ApplicationController
end end
def index def index
@bans = Ban.paginated_search(params) @bans = Ban.paginated_search(params, count_pages: true)
respond_with(@bans) do |fmt| respond_with(@bans) do |fmt|
fmt.html { @bans = @bans.includes(:user, :banner) } fmt.html { @bans = @bans.includes(:user, :banner) }
end end
@@ -42,7 +42,7 @@ class BulkUpdateRequestsController < ApplicationController
end end
def index 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) respond_with(@bulk_update_requests)
end end
+1 -1
View File
@@ -5,7 +5,7 @@ class CommentVotesController < ApplicationController
rescue_with CommentVote::Error, ActiveRecord::RecordInvalid, status: 422 rescue_with CommentVote::Error, ActiveRecord::RecordInvalid, status: 422
def index 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) respond_with(@comment_votes)
end end
+1 -1
View File
@@ -19,7 +19,7 @@ class DmailsController < ApplicationController
if params[:folder] && params[:set_default_folder] if params[:folder] && params[:set_default_folder]
cookies.permanent[:dmail_folder] = params[:folder] cookies.permanent[:dmail_folder] = params[:folder]
end end
@dmails = Dmail.active.visible.paginated_search(params) @dmails = Dmail.active.visible.paginated_search(params, count_pages: true)
respond_with(@dmails) respond_with(@dmails)
end end
@@ -3,7 +3,7 @@ class ForumPostVotesController < ApplicationController
before_action :member_only, only: [:create, :destroy] before_action :member_only, only: [:create, :destroy]
def index 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) respond_with(@forum_post_votes)
end end
+1 -1
View File
@@ -12,7 +12,7 @@ class IpBansController < ApplicationController
end end
def index 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) respond_with(@ip_bans)
end end
+1 -1
View File
@@ -17,7 +17,7 @@ class PoolsController < ApplicationController
end end
def index def index
@pools = Pool.includes(:creator).paginated_search(params) @pools = Pool.includes(:creator).paginated_search(params, count_pages: true)
respond_with(@pools) respond_with(@pools)
end end
+1 -1
View File
@@ -5,7 +5,7 @@ class PostVotesController < ApplicationController
rescue_with PostVote::Error, status: 422 rescue_with PostVote::Error, status: 422
def index 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) respond_with(@post_votes)
end end
+1 -1
View File
@@ -2,7 +2,7 @@ class SavedSearchesController < ApplicationController
respond_to :html, :xml, :json, :js respond_to :html, :xml, :json, :js
def index def index
@saved_searches = saved_searches.paginated_search(params) @saved_searches = saved_searches.paginated_search(params, count_pages: true)
respond_with(@saved_searches) respond_with(@saved_searches)
end end
+1 -1
View File
@@ -22,7 +22,7 @@ class TagAliasesController < ApplicationController
end end
def index 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) respond_with(@tag_aliases)
end end
@@ -22,7 +22,7 @@ class TagImplicationsController < ApplicationController
end end
def index 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) respond_with(@tag_implications)
end end
+1 -1
View File
@@ -24,7 +24,7 @@ class UploadsController < ApplicationController
end end
def index def index
@uploads = Upload.paginated_search(params).includes(:post, :uploader) @uploads = Upload.paginated_search(params, count_pages: true).includes(:post, :uploader)
respond_with(@uploads) respond_with(@uploads)
end end
+1 -1
View File
@@ -20,7 +20,7 @@ class UserFeedbacksController < ApplicationController
end end
def index def index
@user_feedbacks = UserFeedback.visible.paginated_search(params) @user_feedbacks = UserFeedback.visible.paginated_search(params, count_pages: true)
respond_with(@user_feedbacks) respond_with(@user_feedbacks)
end end
+2 -2
View File
@@ -7,9 +7,9 @@ class ApplicationRecord < ActiveRecord::Base
extending(PaginationExtension).paginate(*options) extending(PaginationExtension).paginate(*options)
end end
def paginated_search(params) def paginated_search(params, count_pages: params[:search].present?)
search_params = params.fetch(:search, {}).permit! 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 end
end end