From 34c39b65bb09b86df51b90a2c1cfa54c3bf705ff Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Wed, 13 May 2020 11:09:40 +0800 Subject: [PATCH] PERF: Avoid executing the same query twice. --- app/models/topic_tracking_state.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/topic_tracking_state.rb b/app/models/topic_tracking_state.rb index 015e1b0c11..244ce472b9 100644 --- a/app/models/topic_tracking_state.rb +++ b/app/models/topic_tracking_state.rb @@ -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(