posts: fix error on post index page when search count times out in safe mode
Fix a nil deference error on the post index page. This happened when performing a single tag search in safe mode and calculating the number of search results timed out.
This commit is contained in:
@@ -201,6 +201,7 @@ class PostQuery
|
|||||||
end
|
end
|
||||||
|
|
||||||
concerning :CountMethods do
|
concerning :CountMethods do
|
||||||
|
# @return [Integer, nil] The number of posts returned by the search, or nil on timeout.
|
||||||
def post_count
|
def post_count
|
||||||
@post_count ||= fast_count
|
@post_count ||= fast_count
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ module PostSets
|
|||||||
|
|
||||||
# The description of the page for the <meta name="description"> tag.
|
# The description of the page for the <meta name="description"> tag.
|
||||||
def meta_description
|
def meta_description
|
||||||
if post_query.is_simple_tag?
|
# XXX post_count may be nil if the search times out because of safe mode
|
||||||
|
if normalized_query.is_simple_tag? && post_count.present?
|
||||||
humanized_count = ApplicationController.helpers.humanized_number(post_count, million: " million", thousand: " thousand")
|
humanized_count = ApplicationController.helpers.humanized_number(post_count, million: " million", thousand: " thousand")
|
||||||
humanized_count = "over #{humanized_count}" if post_count >= 1_000
|
humanized_count = "over #{humanized_count}" if post_count >= 1_000
|
||||||
|
|
||||||
@@ -108,6 +109,7 @@ module PostSets
|
|||||||
@posts ||= normalized_query.paginated_posts(page, includes: includes, count: post_count, search_count: !post_count.nil?, limit: per_page, max_limit: max_per_page).load
|
@posts ||= normalized_query.paginated_posts(page, includes: includes, count: post_count, search_count: !post_count.nil?, limit: per_page, max_limit: max_per_page).load
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @return [Integer, nil] The number of posts returned by the search, or nil if unknown.
|
||||||
def post_count
|
def post_count
|
||||||
normalized_query.post_count
|
normalized_query.post_count
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -234,6 +234,13 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
assert_response 410
|
assert_response 410
|
||||||
assert_select "h1", "Search Error"
|
assert_select "h1", "Search Error"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "render if the search count times out" do
|
||||||
|
PostQuery.any_instance.stubs(:exact_count).returns(nil)
|
||||||
|
get posts_path, params: { tags: "1girl", safe_mode: "true" }
|
||||||
|
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with a pool: search" do
|
context "with a pool: search" do
|
||||||
|
|||||||
Reference in New Issue
Block a user