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:
parent
a2851b5d4c
commit
ba3078e098
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue