diff --git a/app/controllers/modqueue_controller.rb b/app/controllers/modqueue_controller.rb index ef786ec24..9ed387dbf 100644 --- a/app/controllers/modqueue_controller.rb +++ b/app/controllers/modqueue_controller.rb @@ -6,7 +6,7 @@ class ModqueueController < ApplicationController authorize :modqueue @posts = Post.includes(:appeals, :disapprovals, :uploader, flags: [:creator]).in_modqueue.available_for_moderation(CurrentUser.user, hidden: search_params[:hidden]) @modqueue_posts = @posts.reselect(nil).reorder(nil).offset(nil).limit(nil) - @posts = @posts.paginated_search(params, order: "modqueue", count_pages: true, count: @modqueue_posts.to_a.size) + @posts = @posts.paginated_search(params, count_pages: true, count: @modqueue_posts.to_a.size, defaults: { order: "modqueue" }) @pending_post_count = @modqueue_posts.select(&:is_pending?).count @flagged_post_count = @modqueue_posts.select(&:is_flagged?).count diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 78675e6de..85aae3f1d 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -16,19 +16,20 @@ class ApplicationRecord < ActiveRecord::Base # Perform a search using the model's `search` method, then paginate the results. # - # params [Hash] The URL request params from the user - # page [Integer] The page number - # limit [Integer] The number of posts per page - # count_pages [Boolean] If true, show the exact number of pages of - # results. If false (the default), don't count the exact number of pages + # @param params [Hash] The URL request params from the user + # @param page [Integer] The page number + # @param limit [Integer] The number of posts per page + # @param count_pages [Boolean] If true, calculate the exact number of pages of + # results. If false (the default), don't calculate the exact number of pages # of results; assume there are too many pages to count. - # defaults [Hash] The default params for the search - def paginated_search(params, page: params[:page], limit: params[:limit], count_pages: params[:search].present?, defaults: {}) + # @param count [Integer] the precalculated number of search results, or nil to calculate it + # @param defaults [Hash] The default params for the search + def paginated_search(params, page: params[:page], limit: params[:limit], count_pages: params[:search].present?, count: nil, defaults: {}) search_params = params.fetch(:search, {}).permit! search_params = defaults.merge(search_params).with_indifferent_access max_limit = (params[:format] == "sitemap") ? 10_000 : 1_000 - search(search_params).paginate(page, limit: limit, max_limit: max_limit, search_count: count_pages) + search(search_params).paginate(page, limit: limit, max_limit: max_limit, count: count, search_count: count_pages) end end end