This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
2021-04-24 08:01:43 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class AccountSuggestions::GlobalSource < AccountSuggestions::Source
|
2022-04-28 08:47:34 -07:00
|
|
|
include Redisable
|
|
|
|
|
2021-04-24 08:01:43 -07:00
|
|
|
def key
|
|
|
|
:global
|
|
|
|
end
|
|
|
|
|
|
|
|
def get(account, skip_account_ids: [], limit: 40)
|
2022-02-08 13:23:04 -08:00
|
|
|
account_ids = account_ids_for_locale(I18n.locale.to_s.split(/[_-]/).first) - [account.id] - skip_account_ids
|
2021-04-24 08:01:43 -07:00
|
|
|
|
|
|
|
as_ordered_suggestions(
|
|
|
|
scope(account).where(id: account_ids),
|
|
|
|
account_ids
|
|
|
|
).take(limit)
|
|
|
|
end
|
|
|
|
|
|
|
|
def remove(_account, _target_account_id)
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def scope(account)
|
|
|
|
Account.searchable
|
|
|
|
.followable_by(account)
|
|
|
|
.not_excluded_by_account(account)
|
|
|
|
.not_domain_blocked_by_account(account)
|
|
|
|
end
|
|
|
|
|
|
|
|
def account_ids_for_locale(locale)
|
2022-04-28 08:47:34 -07:00
|
|
|
redis.zrevrange("follow_recommendations:#{locale}", 0, -1).map(&:to_i)
|
2021-04-24 08:01:43 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_ordered_list_key(account)
|
|
|
|
account.id
|
|
|
|
end
|
|
|
|
end
|