always do a count search for cases where fast_count returns 0
This commit is contained in:
@@ -595,26 +595,34 @@ class Post < ActiveRecord::Base
|
|||||||
|
|
||||||
def fast_count(tags = "")
|
def fast_count(tags = "")
|
||||||
tags = tags.to_s.strip
|
tags = tags.to_s.strip
|
||||||
|
|
||||||
count = get_count_from_cache(tags)
|
count = get_count_from_cache(tags)
|
||||||
if count.nil?
|
|
||||||
if tags.blank? && Danbooru.config.blank_tag_search_fast_count
|
|
||||||
count = Danbooru.config.blank_tag_search_fast_count
|
|
||||||
else
|
|
||||||
count = Post.with_timeout(500, Danbooru.config.blank_tag_search_fast_count || 1_000_000) do
|
|
||||||
Post.tag_match(tags).undeleted.count
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if count > Danbooru.config.posts_per_page * 10
|
if count.nil?
|
||||||
set_count_in_cache(tags, count)
|
fast_count_search(tags)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
count.to_i
|
count.to_i
|
||||||
rescue SearchError
|
rescue SearchError
|
||||||
0
|
0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def fast_count_search(tags)
|
||||||
|
if tags.blank? && Danbooru.config.blank_tag_search_fast_count
|
||||||
|
count = Danbooru.config.blank_tag_search_fast_count
|
||||||
|
else
|
||||||
|
count = Post.with_timeout(500, Danbooru.config.blank_tag_search_fast_count || 1_000_000) do
|
||||||
|
Post.tag_match(tags).undeleted.count
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if count == 0
|
||||||
|
count = Post.tag_match(tags).undeleted.count
|
||||||
|
end
|
||||||
|
|
||||||
|
if count > Danbooru.config.posts_per_page * 10
|
||||||
|
set_count_in_cache(tags, count)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module CacheMethods
|
module CacheMethods
|
||||||
|
|||||||
3
script/donmai/delayed_job_count
Executable file
3
script/donmai/delayed_job_count
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
psql -hdbserver -c 'select count(*) from delayed_jobs' -Pt -A danbooru2 > /tmp/delayed_job_count
|
||||||
Reference in New Issue
Block a user