refactored with_timeout helper
This commit is contained in:
@@ -600,13 +600,8 @@ class Post < ActiveRecord::Base
|
||||
if tags.blank? && Danbooru.config.blank_tag_search_fast_count
|
||||
count = Danbooru.config.blank_tag_search_fast_count
|
||||
else
|
||||
begin
|
||||
ActiveRecord::Base.connection.execute("SET statement_timeout = 500")
|
||||
count = Post.tag_match(tags).undeleted.count
|
||||
rescue ActiveRecord::StatementInvalid
|
||||
count = Danbooru.config.blank_tag_search_fast_count || 1_000_000
|
||||
ensure
|
||||
ActiveRecord::Base.connection.execute("SET statement_timeout = 3000")
|
||||
count = Post.with_timeout(500, Danbooru.config.blank_tag_search_fast_count || 1_000_000) do
|
||||
Post.tag_match(tags).undeleted.count
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -6,8 +6,11 @@ module PostSetPresenters
|
||||
|
||||
def post_previews_html(template)
|
||||
html = ""
|
||||
is_empty = Post.with_timeout(500, false) do
|
||||
posts.empty?
|
||||
end
|
||||
|
||||
if posts.empty?
|
||||
if is_empty?
|
||||
return template.render("post_sets/blank")
|
||||
end
|
||||
|
||||
|
||||
@@ -8,14 +8,16 @@ module Danbooru
|
||||
connection.execute("SET STATEMENT_TIMEOUT = 0") unless Rails.env == "test"
|
||||
yield
|
||||
ensure
|
||||
connection.execute("SET STATEMENT_TIMEOUT = 5000") unless Rails.env == "test"
|
||||
connection.execute("SET STATEMENT_TIMEOUT = 3000") unless Rails.env == "test"
|
||||
end
|
||||
|
||||
def with_timeout(n)
|
||||
def with_timeout(n, default_value)
|
||||
connection.execute("SET STATEMENT_TIMEOUT = #{n}") unless Rails.env == "test"
|
||||
yield
|
||||
rescue ActiveRecord::StatementInvalid
|
||||
return default_value
|
||||
ensure
|
||||
connection.execute("SET STATEMENT_TIMEOUT = 5000") unless Rails.env == "test"
|
||||
connection.execute("SET STATEMENT_TIMEOUT = 3000") unless Rails.env == "test"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user