Skip to content

Commit

Permalink
PERF: Avoid executing the same query twice.
Browse files Browse the repository at this point in the history
  • Loading branch information
tgxworld committed May 13, 2020
1 parent 822e594 commit 34c39b6
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/models/topic_tracking_state.rb
Expand Up @@ -195,14 +195,16 @@ def self.report(user, topic_id = nil)
#
# 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,
skip_order: true,
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"
Expand All @@ -215,7 +217,7 @@ def self.report(user, topic_id = nil)
filter_old_unread: true,
admin: user.admin?,
user: user,
muted_tag_ids: muted_tag_ids(user)
muted_tag_ids: tag_ids
)

DB.query(
Expand Down

1 comment on commit 34c39b6

@discoursereviewbot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SamSaffron posted:

Nice catch fyi @lis2

Please sign in to comment.