2023-12-19 21:59:43 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class AccountSuggestions::FriendsOfFriendsSource < AccountSuggestions::Source
|
2024-02-20 20:21:49 +11:00
|
|
|
def get(account, limit: DEFAULT_LIMIT)
|
2024-03-04 17:35:20 +11:00
|
|
|
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] }
|
2023-12-19 21:59:43 +11:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def key
|
|
|
|
:friends_of_friends
|
|
|
|
end
|
|
|
|
end
|