You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
848 B

  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(I18n.locale.to_s.split(/[_-]/).first) - [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