optimize Post.fast_count for some basic queries

This commit is contained in:
r888888888
2016-01-02 09:45:59 -08:00
parent c280760b44
commit 05adc679a3

View File

@@ -1029,22 +1029,26 @@ class Post < ActiveRecord::Base
"pfc:#{Cache.sanitize(tags)}" "pfc:#{Cache.sanitize(tags)}"
end end
def slow_query?(tags)
tags.blank?
end
def fast_count(tags = "", options = {}) def fast_count(tags = "", options = {})
tags = tags.to_s.strip tags = tags.to_s.strip
max_count = Danbooru.config.blank_tag_search_fast_count
if max_count && slow_query?(tags) if tags == ""
count = max_count return Post.maximum(:id) * (2200402.0 / 2232212)
else
count = get_count_from_cache(tags)
if count.to_i == 0 elsif tags == "rating:s"
count = fast_count_search(tags, options) return Post.maximum(:id) * (1648652.0 / 2200402)
end
elsif tags == "rating:q"
return Post.maximum(:id) * (350101.0 / 2200402)
elsif tags == "rating:e"
return Post.maximum(:id) * (201650.0 / 2200402)
end
count = get_count_from_cache(tags)
if count.to_i == 0
count = fast_count_search(tags, options)
end end
count.to_i count.to_i