global_source.rb 831 B

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