From 05adc679a3557db7a470bd845e324fd57bf1d9f4 Mon Sep 17 00:00:00 2001 From: r888888888 Date: Sat, 2 Jan 2016 09:45:59 -0800 Subject: [PATCH] optimize Post.fast_count for some basic queries --- app/models/post.rb | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/app/models/post.rb b/app/models/post.rb index 3a89cca69..cffc877ef 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -1029,22 +1029,26 @@ class Post < ActiveRecord::Base "pfc:#{Cache.sanitize(tags)}" end - def slow_query?(tags) - tags.blank? - end - def fast_count(tags = "", options = {}) tags = tags.to_s.strip - max_count = Danbooru.config.blank_tag_search_fast_count - if max_count && slow_query?(tags) - count = max_count - else - count = get_count_from_cache(tags) + if tags == "" + return Post.maximum(:id) * (2200402.0 / 2232212) - if count.to_i == 0 - count = fast_count_search(tags, options) - end + elsif tags == "rating:s" + return Post.maximum(:id) * (1648652.0 / 2200402) + + 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 count.to_i