diff --git a/app/models/topic_hot_score.rb b/app/models/topic_hot_score.rb index a2f8c6d9b85..570f163cabd 100644 --- a/app/models/topic_hot_score.rb +++ b/app/models/topic_hot_score.rb @@ -141,7 +141,7 @@ class TopicHotScore < ActiveRecord::Base FROM topics WHERE topics.id IN ( SELECT topic_id FROM topic_ids - ) AND ths.topic_id = topics.id + ) AND ths.topic_id = topics.id AND topics.created_at <= :now SQL DB.exec(sql, args) diff --git a/spec/models/topic_hot_scores_spec.rb b/spec/models/topic_hot_scores_spec.rb index 89e61356fa2..e2882fc6cd7 100644 --- a/spec/models/topic_hot_scores_spec.rb +++ b/spec/models/topic_hot_scores_spec.rb @@ -111,5 +111,18 @@ RSpec.describe TopicHotScore do expect(TopicHotScore.find_by(topic_id: topic1.id).score).to be_within(0.0001).of(0.0005) expect(TopicHotScore.find_by(topic_id: topic2.id).score).to be_within(0.001).of(0.001) end + + it "ignores topics in the future" do + freeze_time + + topic1 = Fabricate(:topic, like_count: 3, created_at: 2.days.from_now) + post1 = Fabricate(:post, topic: topic1, created_at: 1.minute.ago) + PostActionCreator.like(user, post1) + TopicHotScore.create!(topic_id: topic1.id, score: 0.0, recent_likes: 0, recent_posters: 0) + + expect { TopicHotScore.update_scores }.not_to change { + TopicHotScore.where(topic_id: topic1.id).pluck(:recent_likes) + } + end end end