From b7ff4173c9b4696035c11eb31e70fe356ba40be0 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 27 Mar 2014 15:43:24 +1100 Subject: [PATCH] BUGFIX: mitigate unbound table growth on top_topics --- app/models/top_topic.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/models/top_topic.rb b/app/models/top_topic.rb index 7ac852ff8fe..81f5e59fdbc 100644 --- a/app/models/top_topic.rb +++ b/app/models/top_topic.rb @@ -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