about summary refs log tree commit diff
path: root/app/models/account.rb
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-10-29 01:29:19 +0200
committerEugen Rochko <eugen@zeonfederated.com>2016-10-29 01:29:19 +0200
commite0a197650a30bec9dae26d714168700bc9ce93ed (patch)
tree5f590c5b2f393734be7aea5e19c1ecaa8c85857f /app/models/account.rb
parentc913bdfc98baab25a78866d5d2b0f0c33e017afa (diff)
Adding common followers API, fixing fallback query again
Diffstat (limited to 'app/models/account.rb')
-rw-r--r--app/models/account.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/app/models/account.rb b/app/models/account.rb
index 8eba4da79..2e1f7a448 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -122,6 +122,15 @@ class Account < ApplicationRecord
     username
   end
 
+  def common_followers_with(other_account)
+    results  = Neography::Rest.new.execute_query('MATCH (a {account_id: {a_id}})-[:follows]->(b)-[:follows]->(c {account_id: {c_id}}) RETURN b.account_id', a_id: id, c_id: other_account.id)
+    ids      = results['data'].map(&:first)
+    accounts = self.where(id: ids).with_counters.map { |a| [a.id, a] }.to_h
+    ids.map { |id| accounts[id] }.compact
+  rescue Neography::NeographyError, Excon::Error::Socket
+    []
+  end
+
   def self.find_local!(username)
     find_remote!(username, nil)
   end