mirror of
https://github.com/mastodon/mastodon.git
synced 2025-09-06 09:51:24 +00:00

Some checks are pending
Check i18n / check-i18n (push) Waiting to run
Chromatic / Run Chromatic (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (ruby) (push) Waiting to run
Check formatting / lint (push) Waiting to run
JavaScript Linting / lint (push) Waiting to run
Ruby Linting / lint (push) Waiting to run
JavaScript Testing / test (push) Waiting to run
Historical data migration test / test (14-alpine) (push) Waiting to run
Historical data migration test / test (15-alpine) (push) Waiting to run
Historical data migration test / test (16-alpine) (push) Waiting to run
Historical data migration test / test (17-alpine) (push) Waiting to run
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / test (3.2) (push) Blocked by required conditions
Ruby Testing / test (3.3) (push) Blocked by required conditions
Ruby Testing / ImageMagick tests (.ruby-version) (push) Blocked by required conditions
Ruby Testing / ImageMagick tests (3.2) (push) Blocked by required conditions
Ruby Testing / ImageMagick tests (3.3) (push) Blocked by required conditions
Ruby Testing / End to End testing (.ruby-version) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.2) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.3) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.10.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.2, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
49 lines
2.4 KiB
Ruby
49 lines
2.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class AccountSuggestions::FriendsOfFriendsSource < AccountSuggestions::Source
|
|
def get(account, limit: DEFAULT_LIMIT)
|
|
source_query(account, limit: limit)
|
|
.map { |id, _frequency, _followers_count| [id, key] }
|
|
end
|
|
|
|
def source_query(account, limit: DEFAULT_LIMIT)
|
|
Account.find_by_sql([<<~SQL.squish, { id: account.id, limit: limit }]).map { |row| [row.id, row.frequency, row.followers_count] }
|
|
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, account_stats.followers_count as followers_count
|
|
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 blocks b WHERE b.target_account_id = follows.target_account_id AND b.account_id = :id)
|
|
AND NOT EXISTS (SELECT 1 FROM blocks b WHERE b.target_account_id = :id AND b.account_id = follows.target_account_id)
|
|
AND NOT EXISTS (SELECT 1 FROM mutes m WHERE m.target_account_id = follows.target_account_id AND m.account_id = :id)
|
|
AND (accounts.domain IS NULL OR NOT EXISTS (SELECT 1 FROM account_domain_blocks b WHERE b.account_id = :id AND b.domain = accounts.domain))
|
|
AND NOT EXISTS (SELECT 1 FROM follows f WHERE f.target_account_id = follows.target_account_id AND f.account_id = :id)
|
|
AND NOT EXISTS (SELECT 1 FROM follow_requests 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 accounts.memorial = FALSE
|
|
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
|
|
|
|
def key
|
|
:friends_of_friends
|
|
end
|
|
end
|