throw error on counts/posts endpoint during a timeout (#2170)
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
class CountsController < ApplicationController
|
class CountsController < ApplicationController
|
||||||
respond_to :xml, :json
|
respond_to :xml, :json
|
||||||
|
rescue_from Post::TimeoutError, with: :rescue_exception
|
||||||
|
|
||||||
def posts
|
def posts
|
||||||
@count = Post.fast_count(params[:tags])
|
@count = Post.fast_count(params[:tags], raise_on_timeout: true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ class Post < ApplicationRecord
|
|||||||
class RevertError < Exception ; end
|
class RevertError < Exception ; end
|
||||||
class SearchError < Exception ; end
|
class SearchError < Exception ; end
|
||||||
class DeletionError < Exception ; end
|
class DeletionError < Exception ; end
|
||||||
|
class TimeoutError < Exception ; end
|
||||||
|
|
||||||
# Tags to copy when copying notes.
|
# Tags to copy when copying notes.
|
||||||
NOTE_COPY_TAGS = %w[translated partially_translated check_translation translation_request reverse_translation]
|
NOTE_COPY_TAGS = %w[translated partially_translated check_translation translation_request reverse_translation]
|
||||||
@@ -1202,6 +1203,10 @@ class Post < ApplicationRecord
|
|||||||
|
|
||||||
if count.nil?
|
if count.nil?
|
||||||
# give up
|
# give up
|
||||||
|
if options[:raise_on_timeout]
|
||||||
|
raise TimeoutError.new("timed out")
|
||||||
|
end
|
||||||
|
|
||||||
count = Danbooru.config.blank_tag_search_fast_count
|
count = Danbooru.config.blank_tag_search_fast_count
|
||||||
else
|
else
|
||||||
set_count_in_cache(tags, count)
|
set_count_in_cache(tags, count)
|
||||||
|
|||||||
@@ -7,6 +7,12 @@ class CountsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
get posts_counts_path
|
get posts_counts_path
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "render an error during a timeout" do
|
||||||
|
Post.stubs(:fast_count).raises(Post::TimeoutError.new)
|
||||||
|
get posts_counts_path
|
||||||
|
assert_response :error
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user