changes to limit
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
class LegacyController < ApplicationController
|
class LegacyController < ApplicationController
|
||||||
def posts
|
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
|
@posts = @post_set.posts
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
module PostSets
|
module PostSets
|
||||||
class Post < Base
|
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)
|
@tag_array = Tag.scan_query(tags)
|
||||||
@page = page
|
@page = page
|
||||||
|
@per_page = (per_page || Post.records_per_page).to_i
|
||||||
|
@per_page = 200 if @per_page > 200
|
||||||
end
|
end
|
||||||
|
|
||||||
def tag_string
|
def tag_string
|
||||||
@@ -36,7 +38,7 @@ module PostSets
|
|||||||
raise SearchError.new("Upgrade your account to search more than two tags at once")
|
raise SearchError.new("Upgrade your account to search more than two tags at once")
|
||||||
end
|
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
|
rescue ::Post::SearchError
|
||||||
@posts = ::Post.where("false")
|
@posts = ::Post.where("false")
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ module Danbooru
|
|||||||
|
|
||||||
def records_per_page
|
def records_per_page
|
||||||
# ugly hack but no easy way to pass this info down
|
# 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
|
end
|
||||||
|
|
||||||
# taken from kaminari (https://github.com/amatsuda/kaminari)
|
# taken from kaminari (https://github.com/amatsuda/kaminari)
|
||||||
|
|||||||
Reference in New Issue
Block a user