PERF: Avoid executing the same query twice.

This commit is contained in:
Guo Xiang Tan 2020-05-13 11:09:40 +08:00
parent 822e594fc8
commit 34c39b65bb
No known key found for this signature in database
GPG Key ID: FBD110179AAC1F20

View File

@ -195,6 +195,8 @@ class TopicTrackingState
#
# This code needs to be VERY efficient as it is triggered via the message bus and may steal
# cycles from usual requests
tag_ids = muted_tag_ids(user)
sql = +report_raw_sql(
topic_id: topic_id,
skip_unread: true,
@ -202,7 +204,7 @@ class TopicTrackingState
staff: user.staff?,
admin: user.admin?,
user: user,
muted_tag_ids: muted_tag_ids(user)
muted_tag_ids: tag_ids
)
sql << "\nUNION ALL\n\n"
@ -215,7 +217,7 @@ class TopicTrackingState
filter_old_unread: true,
admin: user.admin?,
user: user,
muted_tag_ids: muted_tag_ids(user)
muted_tag_ids: tag_ids
)
DB.query(