mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: add suggested_topics_unread_max_days_old
This new site setting determines the maximum age of unread topics in suggested. By default if you have any unread topics older than 90 days they will be omitted from suggested. This change was added for 2 reasons: 1. A performance safeguard, some users tend to collect a huge amount of read state so it becomes super expensive to find unread 2. People who collect a large amount of unread are much more interested in recent unread topics vs ancient unread topics, this makes suggested more relevant Also, this is a minor speed up for tests cause 3 expensive tests became 1.
This commit is contained in:
@@ -222,7 +222,15 @@ class TopicQuery
|
||||
)) unless builder.full?
|
||||
|
||||
else
|
||||
builder.add_results(unread_results(topic: topic, per_page: builder.results_left), :high)
|
||||
|
||||
builder.add_results(
|
||||
unread_results(
|
||||
topic: topic,
|
||||
per_page: builder.results_left,
|
||||
max_age: SiteSetting.suggested_topics_unread_max_days_old
|
||||
), :high
|
||||
)
|
||||
|
||||
builder.add_results(new_results(topic: topic, per_page: builder.category_results_left)) unless builder.full?
|
||||
end
|
||||
end
|
||||
@@ -470,12 +478,17 @@ class TopicQuery
|
||||
.order('CASE WHEN topics.user_id = tu.user_id THEN 1 ELSE 2 END')
|
||||
|
||||
if @user
|
||||
|
||||
# micro optimisation so we don't load up all of user stats which we do not need
|
||||
unread_at = DB.query_single(
|
||||
"select first_unread_at from user_stats where user_id = ?",
|
||||
@user.id).first
|
||||
|
||||
if max_age = options[:max_age]
|
||||
max_age_date = max_age.days.ago
|
||||
unread_at ||= max_age_date
|
||||
unread_at = unread_at > max_age_date ? unread_at : max_age_date
|
||||
end
|
||||
|
||||
# perf note, in the past we tried doing this in a subquery but performance was
|
||||
# terrible, also tried with a join and it was bad
|
||||
result = result.where("topics.updated_at >= ?", unread_at)
|
||||
|
||||
Reference in New Issue
Block a user