mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
PERF: Don't calculate the same query twice.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user