diff --git a/app/models/top_topic.rb b/app/models/top_topic.rb index eb118f1069e..142b0c1d7fb 100644 --- a/app/models/top_topic.rb +++ b/app/models/top_topic.rb @@ -47,7 +47,7 @@ class TopTopic < ActiveRecord::Base end def self.update_views_count_for(period) - sql = "SELECT parent_id as topic_id, GREATEST(COUNT(*), 1) AS count + sql = "SELECT parent_id as topic_id, COUNT(*) AS count FROM views v WHERE v.viewed_at >= :from GROUP BY topic_id" @@ -56,7 +56,7 @@ class TopTopic < ActiveRecord::Base end def self.update_likes_count_for(period) - sql = "SELECT topic_id, SUM(like_count) AS count + sql = "SELECT topic_id, GREATEST(SUM(like_count), 1) AS count FROM posts p WHERE p.created_at >= :from AND p.deleted_at IS NULL diff --git a/lib/topic_query.rb b/lib/topic_query.rb index b7064cf1d19..bdde8255ce2 100644 --- a/lib/topic_query.rb +++ b/lib/topic_query.rb @@ -88,6 +88,7 @@ class TopicQuery score = "#{period}_score" create_list(:top, unordered: true) do |topics| topics.joins(:top_topic) + .where("top_topics.#{score} > 1") .order("top_topics.#{score} DESC, topics.bumped_at DESC") end end