PERF: Avoid executing the same query twice.

PERF: Avoid executing the same query twice.

diff --git a/app/models/topic_tracking_state.rb b/app/models/topic_tracking_state.rb
index 015e1b0..244ce47 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(

GitHub sha: 34c39b65

2 Likes

Nice catch fyi @lis2

1 Like