PERF: improve 'has_enough_topics_to_redirect_to_top' for high scale

This commit is contained in:
Régis Hanol 2014-06-17 11:26:36 +02:00
parent 737cb47307
commit 43496958fe

View file

@ -88,7 +88,10 @@ class SiteSetting < ActiveRecord::Base
def self.has_enough_topics_to_redirect_to_top
TopTopic.periods.each do |period|
return true if TopTopic.where("#{period}_score > 0").count >= SiteSetting.topics_per_period_in_top_page
topics_per_period = TopTopic.where("#{period}_score > 0")
.limit(SiteSetting.topics_per_period_in_top_page)
.count
return true if topics_per_period >= SiteSetting.topics_per_period_in_top_page
end
# nothing
false