PERF: Don't calculate the same query twice.

This commit is contained in:
Guo Xiang Tan
2016-11-24 10:29:44 +08:00
parent 857955dd04
commit b889bfefbb
4 changed files with 17 additions and 14 deletions

View File

@@ -99,8 +99,8 @@ class SiteSetting < ActiveRecord::Base
end
def self.min_redirected_to_top_period(duration)
period = ListController.best_period_for(duration)
return period if TopTopic.topics_per_period(period) >= SiteSetting.topics_per_period_in_top_page
period = ListController.best_period_with_topics_for(duration)
return period if period
# not enough topics
nil

View File

@@ -4,12 +4,6 @@ class TopTopic < ActiveRecord::Base
belongs_to :topic
def self.topics_per_period(period)
DistributedMemoizer.memoize("#{Discourse.current_hostname}_topics_per_period_#{period}", 1.day) do
TopTopic.where("#{period}_score > 0").count
end.to_i
end
# The top topics we want to refresh often
def self.refresh_daily!
transaction do