mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 02:40:53 -06:00
PERF: optimise new/unread query
This is part 1 of the work, need some internal cleanup to follow new query seems to handle very large sets very efficiently
This commit is contained in:
parent
42925b46b8
commit
bc8c6d1a97
@ -128,13 +128,9 @@ class TopicTrackingState
|
||||
# cycles from usual requests
|
||||
#
|
||||
#
|
||||
sql = report_raw_sql(topic_id: topic_id)
|
||||
|
||||
sql = <<SQL
|
||||
WITH x AS (
|
||||
#{sql}
|
||||
) SELECT * FROM x LIMIT #{SiteSetting.max_tracked_new_unread.to_i}
|
||||
SQL
|
||||
sql = report_raw_sql(topic_id: topic_id, skip_unread: true, skip_order: true)
|
||||
sql << "\nUNION ALL\n\n"
|
||||
sql << report_raw_sql(topic_id: topic_id, skip_new: true, skip_order: true)
|
||||
|
||||
SqlBuilder.new(sql)
|
||||
.map_exec(TopicTrackingState, user_id: user_id, topic_id: topic_id)
|
||||
@ -198,7 +194,11 @@ SQL
|
||||
sql << " AND topics.id = :topic_id"
|
||||
end
|
||||
|
||||
sql << " ORDER BY topics.bumped_at DESC"
|
||||
unless opts && opts[:skip_order]
|
||||
sql << " ORDER BY topics.bumped_at DESC"
|
||||
end
|
||||
|
||||
sql
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user