global_source.rb 861 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. # frozen_string_literal: true
  2. class AccountSuggestions::GlobalSource < AccountSuggestions::Source
  3. include Redisable
  4. def key
  5. :global
  6. end
  7. def get(account, skip_account_ids: [], limit: 40)
  8. account_ids = account_ids_for_locale(I18n.locale.to_s.split(/[_-]/).first) - [account.id] - skip_account_ids
  9. as_ordered_suggestions(
  10. scope(account).where(id: account_ids),
  11. account_ids
  12. ).take(limit)
  13. end
  14. def remove(_account, _target_account_id)
  15. nil
  16. end
  17. private
  18. def scope(account)
  19. Account.searchable
  20. .followable_by(account)
  21. .not_excluded_by_account(account)
  22. .not_domain_blocked_by_account(account)
  23. end
  24. def account_ids_for_locale(locale)
  25. redis.zrevrange("follow_recommendations:#{locale}", 0, -1).map(&:to_i)
  26. end
  27. def to_ordered_list_key(account)
  28. account.id
  29. end
  30. end