Skip to content

Commit

Permalink
PERF: Use different column for better query plan (#14748)
Browse files Browse the repository at this point in the history
Using topics.id provides a better query plan than posts.topic_id which
speeds up search by almost 50%.
  • Loading branch information
udan11 committed Oct 28, 2021
1 parent a2851b5 commit ba3078e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/models/post.rb
Expand Up @@ -86,8 +86,8 @@ class Post < ActiveRecord::Base

scope :private_posts_for_user, ->(user) do
where(
"posts.topic_id IN (#{Topic::PRIVATE_MESSAGES_SQL_USER})
OR posts.topic_id IN (#{Topic::PRIVATE_MESSAGES_SQL_GROUP})",
"topics.id IN (#{Topic::PRIVATE_MESSAGES_SQL_USER})
OR topics.id IN (#{Topic::PRIVATE_MESSAGES_SQL_GROUP})",
user_id: user.id
)
end
Expand Down

0 comments on commit ba3078e

Please sign in to comment.