FEATURE: improvements to hot feature (#25533)

1. Don't show visited line for hot filter, it is in random order
2. Don't count likes on non regular posts (eg: whispers / small actions)
3. Don't count participants in non regular posts
This commit is contained in:
Sam 2024-02-02 10:53:27 +11:00 committed by GitHub
parent 9563d02054
commit 140b2118af
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 29 additions and 5 deletions

View File

@ -81,6 +81,7 @@
<TopicList
@highlightLastVisited={{true}}
@top={{this.top}}
@hot={{this.hot}}
@showTopicPostBadges={{this.showTopicPostBadges}}
@showPosters={{true}}
@canBulkSelect={{@canBulkSelect}}

View File

@ -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";
}

View File

@ -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
);
},

View File

@ -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

View File

@ -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