]> cat aescling's git repositories - mastodon.git/commitdiff
Simplify SQL query when performing account search amongst followings (#12302)
authorThibG <thib@sitedethib.com>
Thu, 21 Nov 2019 16:35:04 +0000 (17:35 +0100)
committerEugen Rochko <eugen@zeonfederated.com>
Thu, 21 Nov 2019 16:35:04 +0000 (17:35 +0100)
app/models/account.rb

index cae82da1627bbc39fe4a1767385f0d233fe7cda2..d17782f78d2b0188a1cf6a23f5291a1daebd537a 100644 (file)
@@ -436,7 +436,7 @@ class Account < ApplicationRecord
             accounts.*,
             (count(f.id) + 1) * ts_rank_cd(#{textsearch}, #{query}, 32) AS rank
           FROM accounts
-          LEFT OUTER JOIN follows AS f ON (accounts.id = f.account_id AND f.target_account_id = ?) OR (accounts.id = f.target_account_id AND f.account_id = ?)
+          LEFT OUTER JOIN follows AS f ON (accounts.id = f.account_id AND f.target_account_id = ?)
           WHERE accounts.id IN (SELECT * FROM first_degree)
             AND #{query} @@ #{textsearch}
             AND accounts.suspended_at IS NULL
@@ -446,7 +446,7 @@ class Account < ApplicationRecord
           LIMIT ? OFFSET ?
         SQL
 
-        records = find_by_sql([sql, account.id, account.id, account.id, account.id, limit, offset])
+        records = find_by_sql([sql, account.id, account.id, account.id, limit, offset])
       else
         sql = <<-SQL.squish
           SELECT