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

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%.

diff --git a/app/models/post.rb b/app/models/post.rb
index 5a8488e..7120db5 100644
--- a/app/models/post.rb
+++ b/app/models/post.rb
@@ -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

GitHub sha: ba3078e0980d82cee0064a18c51407dcc4202b25

This commit appears in #14748 which was approved by pmusaraj. It was merged by udan11.