diff --git a/app/controllers/legacy_controller.rb b/app/controllers/legacy_controller.rb index cbc221b5e..b74125c93 100644 --- a/app/controllers/legacy_controller.rb +++ b/app/controllers/legacy_controller.rb @@ -1,6 +1,6 @@ class LegacyController < ApplicationController def posts - @post_set = PostSets::Post.new(tag_query, params[:page]) + @post_set = PostSets::Post.new(tag_query, params[:page], params[:limit]) @posts = @post_set.posts end diff --git a/app/logical/post_sets/post.rb b/app/logical/post_sets/post.rb index 30c47726d..830373a21 100644 --- a/app/logical/post_sets/post.rb +++ b/app/logical/post_sets/post.rb @@ -1,10 +1,12 @@ module PostSets class Post < Base - attr_reader :tag_array, :page + attr_reader :tag_array, :page, :per_page - def initialize(tags, page = 1) + def initialize(tags, page = 1, per_page = nil) @tag_array = Tag.scan_query(tags) @page = page + @per_page = (per_page || Post.records_per_page).to_i + @per_page = 200 if @per_page > 200 end def tag_string @@ -36,7 +38,7 @@ module PostSets raise SearchError.new("Upgrade your account to search more than two tags at once") end - @posts ||= ::Post.tag_match(tag_string).paginate(page, :count => ::Post.fast_count(tag_string)) + @posts ||= ::Post.tag_match(tag_string).paginate(page, :count => ::Post.fast_count(tag_string), :limit => :per_page) rescue ::Post::SearchError @posts = ::Post.where("false") end diff --git a/lib/danbooru/paginator/active_record_extension.rb b/lib/danbooru/paginator/active_record_extension.rb index 608416c31..61e9f3b98 100644 --- a/lib/danbooru/paginator/active_record_extension.rb +++ b/lib/danbooru/paginator/active_record_extension.rb @@ -66,7 +66,7 @@ module Danbooru def records_per_page # ugly hack but no easy way to pass this info down - Thread.current["records_per_page"] || Danbooru.config.posts_per_page + (@paginator_options[:limit] || Thread.current["records_per_page"] || Danbooru.config.posts_per_page).to_i end # taken from kaminari (https://github.com/amatsuda/kaminari)