mirror of
https://github.com/discourse/discourse.git
synced 2025-06-04 07:14:41 +08:00
PERF: Reduce number of topics to filter while querying for unread.
This commit is contained in:
@ -288,8 +288,9 @@ class TopicQuery
|
||||
|
||||
list
|
||||
.where("tu.last_read_post_number < topics.#{col_name}")
|
||||
.where("COALESCE(tu.notification_level, :regular) >= :tracking",
|
||||
regular: TopicUser.notification_levels[:regular], tracking: TopicUser.notification_levels[:tracking])
|
||||
.where("tu.notification_level >= :tracking",
|
||||
tracking: TopicUser.notification_levels[:tracking]
|
||||
)
|
||||
end
|
||||
|
||||
def prioritize_pinned_topics(topics, options)
|
||||
@ -369,6 +370,10 @@ class TopicQuery
|
||||
result
|
||||
end
|
||||
|
||||
def unread_results_redis_key
|
||||
"last_unread_result_bumped_at:#{@user.id}"
|
||||
end
|
||||
|
||||
def unread_results(options = {})
|
||||
result = TopicQuery.unread_filter(
|
||||
default_results(options.reverse_merge(unordered: true)),
|
||||
@ -380,6 +385,17 @@ class TopicQuery
|
||||
result = filter_callback.call(:unread, result, @user, options)
|
||||
end
|
||||
|
||||
if !(last_bumped_at = $redis.get(unread_results_redis_key))
|
||||
last_bumped_at = result.unscope(:limit, :order).order(:bumped_at).first&.bumped_at
|
||||
|
||||
$redis.setex(
|
||||
unread_results_redis_key,
|
||||
1.hour.to_i,
|
||||
(last_bumped_at || Time.zone.now).to_s
|
||||
)
|
||||
end
|
||||
|
||||
result = result.where("topics.bumped_at >= ?", last_bumped_at) if last_bumped_at
|
||||
suggested_ordering(result, options)
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user