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
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
@@ -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
+1 -1
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
+1 -1
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
@@ -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
+1 -1
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
+1 -1
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
+1 -1
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
+2 -2
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
+1 -1
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
@@ -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
+1 -1
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
+1 -1
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
+2 -2
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