diff --git a/app/assets/javascripts/discourse/app/components/discovery/topics.hbs b/app/assets/javascripts/discourse/app/components/discovery/topics.hbs index 8dcea658dea..663818a51aa 100644 --- a/app/assets/javascripts/discourse/app/components/discovery/topics.hbs +++ b/app/assets/javascripts/discourse/app/components/discovery/topics.hbs @@ -81,6 +81,7 @@ = :recent_cutoff AND pa.deleted_at IS NULL @@ -84,10 +88,12 @@ class TopicHotScore < ActiveRecord::Base AND t.archetype <> 'private_message' AND t.deleted_at IS NULL AND p.deleted_at IS NULL + AND p.user_deleted = false AND t.created_at <= :now AND t.bumped_at >= :recent_cutoff AND p.created_at < :now AND p.created_at >= :recent_cutoff + AND p.post_type = :regular GROUP BY t.id ) AS new_values diff --git a/spec/models/topic_hot_scores_spec.rb b/spec/models/topic_hot_scores_spec.rb index 8f2a3ddbea4..407890286a5 100644 --- a/spec/models/topic_hot_scores_spec.rb +++ b/spec/models/topic_hot_scores_spec.rb @@ -34,12 +34,24 @@ RSpec.describe TopicHotScore do hot_scoring = TopicHotScore.find_by(topic_id: topic.id) - expect(hot_scoring.recent_likes).to eq(3) expect(hot_scoring.recent_posters).to eq(2) + expect(hot_scoring.recent_likes).to eq(3) expect(hot_scoring.recent_first_bumped_at).to eq_time(new_reply.created_at) expect(hot_scoring.score).to be_within(0.001).of(1.771) expect(TopicHotScore.find_by(topic_id: -1).recent_likes).to eq(0) + + # make sure we exclude whispers, deleted posts, small posts, etc + whisper = + Fabricate(:post, topic: topic, created_at: 1.hour.ago, post_type: Post.types[:whisper]) + PostActionCreator.like(Fabricate(:admin), whisper) + + TopicHotScore.update_scores + + hot_scoring = TopicHotScore.find_by(topic_id: topic.id) + + expect(hot_scoring.recent_posters).to eq(2) + expect(hot_scoring.recent_likes).to eq(3) end it "prefers recent_likes to topic like count for recent topics" do