about summary refs log tree commit diff
path: root/app/models/account_suggestions/past_interactions_source.rb
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2021-04-24 17:01:43 +0200
committerGitHub <noreply@github.com>2021-04-24 17:01:43 +0200
commitdaccc07dc170627b17564402296f6c8631d0cd97 (patch)
treebb1fea8fde8f44b622b9b39cff46026689dc30ca /app/models/account_suggestions/past_interactions_source.rb
parent863ae47b5145e53c6cc820bd7eff0efd41339e03 (diff)
Change auto-following admin-selected accounts, show in recommendations (#16078)
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