~cytrogen/masto-fe

ref: 86c9c5afa045b9e2cfa41c15db63ad97d58954c1 masto-fe/app/models/account_suggestions/past_interactions_source.rb -rw-r--r-- 787 bytes
86c9c5af — Claire Merge commit '40ba6e119b7457161fd43b449875d0fb9d473c1a' into glitch-soc/merge-upstream 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
35
36
# frozen_string_literal: true

class AccountSuggestions::PastInteractionsSource < AccountSuggestions::Source
  include Redisable

  def key
    :past_interactions
  end

  def get(account, skip_account_ids: [], limit: 40)
    account_ids = account_ids_for_account(account.id, limit + skip_account_ids.size) - skip_account_ids

    as_ordered_suggestions(
      scope.where(id: account_ids),
      account_ids
    ).take(limit)
  end

  def remove(account, target_account_id)
    redis.zrem("interactions:#{account.id}", target_account_id)
  end

  private

  def scope
    Account.searchable
  end

  def account_ids_for_account(account_id, limit)
    redis.zrevrange("interactions:#{account_id}", 0, limit).map(&:to_i)
  end

  def to_ordered_list_key(account)
    account.id
  end
end