BUGFIX: make sure we only show topics that have a useful score in the Top page

This commit is contained in:
Régis Hanol 2014-01-03 01:10:17 +01:00
parent d635d888ba
commit 28bf78d801
2 changed files with 3 additions and 2 deletions

View File

@ -47,7 +47,7 @@ class TopTopic < ActiveRecord::Base
end end
def self.update_views_count_for(period) 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 FROM views v
WHERE v.viewed_at >= :from WHERE v.viewed_at >= :from
GROUP BY topic_id" GROUP BY topic_id"
@ -56,7 +56,7 @@ class TopTopic < ActiveRecord::Base
end end
def self.update_likes_count_for(period) 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 FROM posts p
WHERE p.created_at >= :from WHERE p.created_at >= :from
AND p.deleted_at IS NULL AND p.deleted_at IS NULL

View File

@ -88,6 +88,7 @@ class TopicQuery
score = "#{period}_score" score = "#{period}_score"
create_list(:top, unordered: true) do |topics| create_list(:top, unordered: true) do |topics|
topics.joins(:top_topic) topics.joins(:top_topic)
.where("top_topics.#{score} > 1")
.order("top_topics.#{score} DESC, topics.bumped_at DESC") .order("top_topics.#{score} DESC, topics.bumped_at DESC")
end end
end end