PERF: Use different column for better query plan (#14748)

Using topics.id provides a better query plan than posts.topic_id which
speeds up search by almost 50%.
This commit is contained in:
Dan Ungureanu 2021-10-28 11:30:30 +03:00 committed by GitHub
parent a2851b5d4c
commit ba3078e098
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -86,8 +86,8 @@ class Post < ActiveRecord::Base
scope :private_posts_for_user, ->(user) do scope :private_posts_for_user, ->(user) do
where( where(
"posts.topic_id IN (#{Topic::PRIVATE_MESSAGES_SQL_USER}) "topics.id IN (#{Topic::PRIVATE_MESSAGES_SQL_USER})
OR posts.topic_id IN (#{Topic::PRIVATE_MESSAGES_SQL_GROUP})", OR topics.id IN (#{Topic::PRIVATE_MESSAGES_SQL_GROUP})",
user_id: user.id user_id: user.id
) )
end end