Skip to content

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.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 @@
<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.js
index 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.js
index 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.rb
index 6e874cd050e..5f40ad08438 100644
--- a/app/models/topic_hot_score.rb
+++ b/app/models/topic_hot_score.rb
@@ -21,6 +21,7 @@ class TopicHotScore < ActiveRecord::Base
max: 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::Base
FROM post_actions pa
JOIN posts p2 ON p2.id = pa.post_id
WHERE p2.topic_id = t.id
+ AND p2.post_type = :regular
+ AND p2.deleted_at IS NULL
+ AND p2.user_deleted = false
AND pa.post_action_type_id = 2 -- action_type for 'like'
AND pa.created_at >= :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