~cytrogen/masto-fe

ref: 0664704cd94a356b07870d63971ba11a07d24894 masto-fe/app/models/account_suggestions/source.rb -rw-r--r-- 705 bytes
0664704c — Matt Jankowski Fix Performance/StartWith cop (#24818) 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# frozen_string_literal: true

class AccountSuggestions::Source
  def key
    raise NotImplementedError
  end

  def get(_account, **kwargs)
    raise NotImplementedError
  end

  def remove(_account, target_account_id)
    raise NotImplementedError
  end

  protected

  def as_ordered_suggestions(scope, ordered_list)
    return [] if ordered_list.empty?

    map = scope.index_by { |account| to_ordered_list_key(account) }

    ordered_list.map { |ordered_list_key| map[ordered_list_key] }.compact.map do |account|
      AccountSuggestions::Suggestion.new(
        account: account,
        source: key
      )
    end
  end

  def to_ordered_list_key(_account)
    raise NotImplementedError
  end
end