0
0
Fork 0

Move followable by logic to suggestion class (#28710)

This commit is contained in:
Matt Jankowski 2024-01-12 08:09:33 -05:00 committed by GitHub
parent 608f66f978
commit a90c134850
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 7 deletions

View file

@ -8,11 +8,31 @@ class AccountSuggestions::Source
protected
def base_account_scope(account)
Account.searchable
.followable_by(account)
.not_excluded_by_account(account)
.not_domain_blocked_by_account(account)
.where.not(id: account.id)
.joins("LEFT OUTER JOIN follow_recommendation_mutes ON follow_recommendation_mutes.target_account_id = accounts.id AND follow_recommendation_mutes.account_id = #{account.id}").where(follow_recommendation_mutes: { target_account_id: nil })
Account
.searchable
.where.not(follows_sql, id: account.id)
.where.not(follow_requests_sql, id: account.id)
.not_excluded_by_account(account)
.not_domain_blocked_by_account(account)
.where.not(id: account.id)
.where.not(follow_recommendation_mutes_sql, id: account.id)
end
def follows_sql
<<~SQL.squish
EXISTS (SELECT 1 FROM follows WHERE follows.target_account_id = accounts.id AND follows.account_id = :id)
SQL
end
def follow_requests_sql
<<~SQL.squish
EXISTS (SELECT 1 FROM follow_requests WHERE follow_requests.target_account_id = accounts.id AND follow_requests.account_id = :id)
SQL
end
def follow_recommendation_mutes_sql
<<~SQL.squish
EXISTS (SELECT 1 FROM follow_recommendation_mutes WHERE follow_recommendation_mutes.target_account_id = accounts.id AND follow_recommendation_mutes.account_id = :id)
SQL
end
end