BUGFIX: mitigate unbound table growth on top_topics

This commit is contained in:
Sam 2014-03-27 15:43:24 +11:00
parent b046fab1c4
commit b7ff4173c9

View file

@ -102,7 +102,14 @@ class TopTopic < ActiveRecord::Base
SET #{period}_score = CASE
WHEN #{period}_views_count = 0 THEN 0
ELSE log(#{period}_views_count) + (#{period}_posts_count * #{period}_likes_count)
END")
END
WHERE
#{period}_score <> CASE
WHEN #{period}_views_count = 0 THEN 0
ELSE log(#{period}_views_count) + (#{period}_posts_count * #{period}_likes_count)
END
")
end
def self.start_of(period)
@ -119,7 +126,8 @@ class TopTopic < ActiveRecord::Base
SET #{period}_#{sort}_count = c.count
FROM top_topics tt
INNER JOIN (#{inner_join}) c ON tt.topic_id = c.topic_id
WHERE tt.topic_id = top_topics.topic_id",
WHERE tt.topic_id = top_topics.topic_id
AND tt.#{period}_#{sort}_count <> c.count",
from: start_of(period))
end