2023-12-19 10:59:43 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class AccountSuggestions::FriendsOfFriendsSource < AccountSuggestions::Source
|
2024-02-20 09:21:49 +00:00
|
|
|
def get(account, limit: DEFAULT_LIMIT)
|
2024-03-12 08:38:32 +00:00
|
|
|
source_query(account, limit: limit)
|
|
|
|
.map { |id, _frequency, _followers_count| [id, key] }
|
|
|
|
end
|
|
|
|
|
|
|
|
def source_query(account, limit: DEFAULT_LIMIT)
|
2024-03-04 06:35:20 +00:00
|
|
|
first_degree = account.following.where.not(hide_collections: true).select(:id).reorder(nil)
|
|
|
|
base_account_scope(account)
|
|
|
|
.joins(:account_stat)
|
2024-03-12 08:38:32 +00:00
|
|
|
.joins(:passive_relationships).where(passive_relationships: { account_id: first_degree })
|
2024-03-04 06:35:20 +00:00
|
|
|
.group('accounts.id, account_stats.id')
|
2024-03-12 08:38:32 +00:00
|
|
|
.reorder(frequency: :desc, followers_count: :desc)
|
2024-03-04 06:35:20 +00:00
|
|
|
.limit(limit)
|
2024-03-12 08:38:32 +00:00
|
|
|
.pluck(Arel.sql('accounts.id, COUNT(*) AS frequency, followers_count'))
|
2023-12-19 10:59:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def key
|
|
|
|
:friends_of_friends
|
|
|
|
end
|
|
|
|
end
|