Revert "Fix follow suggestions potentially including silenced or blocked accounts (#29306)"
This reverts commit ee8d0b9447
.
This commit is contained in:
parent
53c2aa797b
commit
2271e6d9cb
5 changed files with 34 additions and 107 deletions
|
@ -2,15 +2,31 @@
|
|||
|
||||
class AccountSuggestions::FriendsOfFriendsSource < AccountSuggestions::Source
|
||||
def get(account, limit: DEFAULT_LIMIT)
|
||||
first_degree = account.following.where.not(hide_collections: true).select(:id).reorder(nil)
|
||||
base_account_scope(account)
|
||||
.joins(:account_stat)
|
||||
.where(id: Follow.where(account_id: first_degree).select(:target_account_id))
|
||||
.group('accounts.id, account_stats.id')
|
||||
.reorder('frequency DESC, followers_count DESC')
|
||||
.limit(limit)
|
||||
.pluck(Arel.sql('accounts.id, COUNT(*) AS frequency'))
|
||||
.map { |id, _frequency| [id, key] }
|
||||
Account.find_by_sql([<<~SQL.squish, { id: account.id, limit: limit }]).map { |row| [row.id, key] }
|
||||
WITH first_degree AS (
|
||||
SELECT target_account_id
|
||||
FROM follows
|
||||
JOIN accounts AS target_accounts ON follows.target_account_id = target_accounts.id
|
||||
WHERE account_id = :id
|
||||
AND NOT target_accounts.hide_collections
|
||||
)
|
||||
SELECT accounts.id, COUNT(*) AS frequency
|
||||
FROM accounts
|
||||
JOIN follows ON follows.target_account_id = accounts.id
|
||||
JOIN account_stats ON account_stats.account_id = accounts.id
|
||||
LEFT OUTER JOIN follow_recommendation_mutes ON follow_recommendation_mutes.target_account_id = accounts.id AND follow_recommendation_mutes.account_id = :id
|
||||
WHERE follows.account_id IN (SELECT * FROM first_degree)
|
||||
AND NOT EXISTS (SELECT 1 FROM follows f WHERE f.target_account_id = follows.target_account_id AND f.account_id = :id)
|
||||
AND follows.target_account_id <> :id
|
||||
AND accounts.discoverable
|
||||
AND accounts.suspended_at IS NULL
|
||||
AND accounts.silenced_at IS NULL
|
||||
AND accounts.moved_to_account_id IS NULL
|
||||
AND follow_recommendation_mutes.target_account_id IS NULL
|
||||
GROUP BY accounts.id, account_stats.id
|
||||
ORDER BY frequency DESC, account_stats.followers_count ASC
|
||||
LIMIT :limit
|
||||
SQL
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -51,8 +51,7 @@ class AccountSuggestions::SimilarProfilesSource < AccountSuggestions::Source
|
|||
recently_followed_account_ids = account.active_relationships.recent.limit(5).pluck(:target_account_id)
|
||||
|
||||
if Chewy.enabled? && !recently_followed_account_ids.empty?
|
||||
ids_from_es = QueryBuilder.new(recently_followed_account_ids, account).build.limit(limit).hits.pluck('_id').map(&:to_i)
|
||||
base_account_scope(account).where(id: ids_from_es).pluck(:id).zip([key].cycle)
|
||||
QueryBuilder.new(recently_followed_account_ids, account).build.limit(limit).hits.pluck('_id').map(&:to_i).zip([key].cycle)
|
||||
else
|
||||
[]
|
||||
end
|
||||
|
|
|
@ -12,8 +12,6 @@ class AccountSuggestions::Source
|
|||
def base_account_scope(account)
|
||||
Account
|
||||
.searchable
|
||||
.where(discoverable: true)
|
||||
.without_silenced
|
||||
.where.not(follows_sql, id: account.id)
|
||||
.where.not(follow_requests_sql, id: account.id)
|
||||
.not_excluded_by_account(account)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue