diff --git a/app/models/account.rb b/app/models/account.rb index fc7359cfc..ae273175b 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -512,12 +512,19 @@ class Account < ApplicationRecord LEFT OUTER JOIN follows AS f ON (accounts.id = f.account_id AND f.target_account_id = :id) OR (accounts.id = f.target_account_id AND f.account_id = :id) LEFT JOIN users ON accounts.id = users.account_id LEFT JOIN account_stats AS s ON accounts.id = s.account_id + LEFT JOIN ( + SELECT target_account_id + FROM follows + WHERE account_id = :id + UNION ALL + SELECT :id + ) AS first_degree ON accounts.id = first_degree.target_account_id WHERE to_tsquery('simple', :tsquery) @@ #{TEXTSEARCH} AND accounts.suspended_at IS NULL AND accounts.moved_to_account_id IS NULL AND (accounts.domain IS NOT NULL OR (users.approved = TRUE AND users.confirmed_at IS NOT NULL)) - GROUP BY accounts.id, s.id - ORDER BY rank DESC + GROUP BY accounts.id, s.id, first_degree.target_account_id + ORDER BY first_degree.target_account_id, rank ASC LIMIT :limit OFFSET :offset SQL end