changes to limit

This commit is contained in:
albert 2013-01-14 16:04:05 -05:00
parent 493990dae1
commit 0cd009df24
3 changed files with 7 additions and 5 deletions

View File

@ -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

View File

@ -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

View File

@ -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)