A platform for community discussion. Free, open, simple.
FEATURE: improvements to hot feature (#25533)
Sam140b2118af26
diff --git a/app/assets/javascripts/discourse/app/components/discovery/topics.hbs b/app/assets/javascripts/discourse/app/components/discovery/topics.hbsindex 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 @@<TopicList@highlightLastVisited={{true}}@top={{this.top}}+ @hot={{this.hot}}@showTopicPostBadges={{this.showTopicPostBadges}}@showPosters={{true}}@canBulkSelect={{@canBulkSelect}}diff --git a/app/assets/javascripts/discourse/app/components/discovery/topics.js b/app/assets/javascripts/discourse/app/components/discovery/topics.jsindex 7e4ff6a1164..bb2e9ae38e4 100644--- a/app/assets/javascripts/discourse/app/components/discovery/topics.js+++ b/app/assets/javascripts/discourse/app/components/discovery/topics.js@@ -43,6 +43,10 @@ export default class DiscoveryTopics extends Component {return filterTypeForMode(this.args.model.filter) === "top";}+ get hot() {+ return filterTypeForMode(this.args.model.filter) === "hot";+ }+get new() {return filterTypeForMode(this.args.model.filter) === "new";}diff --git a/app/assets/javascripts/discourse/app/components/topic-list.js b/app/assets/javascripts/discourse/app/components/topic-list.jsindex 9e4a2b4d4d5..83c43e0eb5a 100644--- a/app/assets/javascripts/discourse/app/components/topic-list.js+++ b/app/assets/javascripts/discourse/app/components/topic-list.js@@ -76,7 +76,7 @@ export default Component.extend(LoadMore, {}},- @observes("topics", "order", "ascending", "category", "top")+ @observes("topics", "order", "ascending", "category", "top", "hot")lastVisitedTopicChanged() {this.refreshLastVisited();},@@ -91,7 +91,7 @@ export default Component.extend(LoadMore, {onScroll.call(this);},- _updateLastVisitedTopic(topics, order, ascending, top) {+ _updateLastVisitedTopic(topics, order, ascending, top, hot) {this.set("lastVisitedTopic", null);if (!this.highlightLastVisited) {@@ -102,7 +102,7 @@ export default Component.extend(LoadMore, {return;}- if (top) {+ if (top || hot) {return;}@@ -156,7 +156,8 @@ export default Component.extend(LoadMore, {this.topics,this.order,this.ascending,- this.top+ this.top,+ this.hot);},diff --git a/app/models/topic_hot_score.rb b/app/models/topic_hot_score.rbindex 6e874cd050e..5f40ad08438 100644--- a/app/models/topic_hot_score.rb+++ b/app/models/topic_hot_score.rb@@ -21,6 +21,7 @@ class TopicHotScore < ActiveRecord::Basemax: max,private_message: Archetype.private_message,recent_cutoff: now - SiteSetting.hot_topics_recent_days.days,+ regular: Post.types[:regular],}# insert up to BATCH_SIZE records that are missing from table@@ -70,6 +71,9 @@ class TopicHotScore < ActiveRecord::BaseFROM post_actions paJOIN posts p2 ON p2.id = pa.post_idWHERE p2.topic_id = t.id+ AND p2.post_type = :regular+ AND p2.deleted_at IS NULL+ AND p2.user_deleted = falseAND pa.post_action_type_id = 2 -- action_type for 'like'AND pa.created_at >= :recent_cutoffAND pa.deleted_at IS NULL@@ -84,10 +88,12 @@ class TopicHotScore < ActiveRecord::BaseAND t.archetype <> 'private_message'AND t.deleted_at IS NULLAND p.deleted_at IS NULL+ AND p.user_deleted = falseAND t.created_at <= :nowAND t.bumped_at >= :recent_cutoffAND p.created_at < :nowAND p.created_at >= :recent_cutoff+ AND p.post_type = :regularGROUP BYt.id) AS new_valuesdiff --git a/spec/models/topic_hot_scores_spec.rb b/spec/models/topic_hot_scores_spec.rbindex 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 dohot_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)endit "prefers recent_likes to topic like count for recent topics" do