about summary refs log tree commit diff
path: root/app/models/account_suggestions/past_interactions_source.rb
diff options
context:
space:
mode:
authorStarfall <us@starfall.systems>2021-05-11 11:19:04 -0500
committerStarfall <us@starfall.systems>2021-05-11 11:19:04 -0500
commitd56731a0b9d73c48bbfbced8732e25587ba892a4 (patch)
treed3830ce2e0292ce07336496e40882c222f455a33 /app/models/account_suggestions/past_interactions_source.rb
parent459a36ab7303db4ee59945b4b2121b25cc86eb38 (diff)
parentffc3f8eebe134ca9b18af73aa29eaa1627082e40 (diff)
Merge branch 'glitch'
Diffstat (limited to 'app/models/account_suggestions/past_interactions_source.rb')
-rw-r--r--app/models/account_suggestions/past_interactions_source.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/app/models/account_suggestions/past_interactions_source.rb b/app/models/account_suggestions/past_interactions_source.rb
new file mode 100644
index 000000000..d169394f1
--- /dev/null
+++ b/app/models/account_suggestions/past_interactions_source.rb
@@ -0,0 +1,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