BUGFIX: mitigate unbound table growth on top_topics
This commit is contained in:
parent
b046fab1c4
commit
b7ff4173c9
|
@ -102,7 +102,14 @@ class TopTopic < ActiveRecord::Base
|
||||||
SET #{period}_score = CASE
|
SET #{period}_score = CASE
|
||||||
WHEN #{period}_views_count = 0 THEN 0
|
WHEN #{period}_views_count = 0 THEN 0
|
||||||
ELSE log(#{period}_views_count) + (#{period}_posts_count * #{period}_likes_count)
|
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
|
end
|
||||||
|
|
||||||
def self.start_of(period)
|
def self.start_of(period)
|
||||||
|
@ -119,7 +126,8 @@ class TopTopic < ActiveRecord::Base
|
||||||
SET #{period}_#{sort}_count = c.count
|
SET #{period}_#{sort}_count = c.count
|
||||||
FROM top_topics tt
|
FROM top_topics tt
|
||||||
INNER JOIN (#{inner_join}) c ON tt.topic_id = c.topic_id
|
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))
|
from: start_of(period))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue