Adding common followers API, fixing fallback query again

This commit is contained in:
Eugen Rochko
2016-10-29 01:29:19 +02:00
parent c913bdfc98
commit e0a197650a
9 changed files with 23 additions and 13 deletions

View File

@ -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