PERF: Keep track of when a users first unread is
This optimisation avoids large scans joining the topics table with the topic_users table. Previously when a user carried a lot of read state we would have to join the entire read state with the topics table. This operation would slow down home page and every topic page. The more read state you accumulated the larger the impact. The optimisation helps people who clean up unread, however if you carry unread from years ago it will only have minimal impact.
This commit is contained in:
@@ -469,6 +469,10 @@ class TopicQuery
|
||||
staff: @user&.staff?)
|
||||
.order('CASE WHEN topics.user_id = tu.user_id THEN 1 ELSE 2 END')
|
||||
|
||||
if @user
|
||||
result = result.where("topics.updated_at >= (SELECT first_unread_at FROM user_stats WHERE user_id = ?)", @user.id)
|
||||
end
|
||||
|
||||
self.class.results_filter_callbacks.each do |filter_callback|
|
||||
result = filter_callback.call(:unread, result, @user, options)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user