about summary refs log tree commit diff
path: root/app/models/follow_suggestion.rb
blob: 108a948a29635bead8f2ce5f366a3f82f39b9383 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
class FollowSuggestion
  def self.get(for_account_id, limit = 6)
    neo = Neography::Rest.new
    account_ids = neo.execute_query('START a=node:account_index(Account={id}) MATCH (a)-[:follows]->(b)-[:follows]->(c) WHERE a <> c AND NOT (a)-[:follows]->(c) RETURN DISTINCT c.account_id', id: for_account_id)
    Account.where(id: account_ids['data'].map(&:first) - Block.where(account_id: for_account_id).pluck(:target_account_id)).limit(limit) unless account_ids.empty?
  rescue Neography::NeographyError, Excon::Error::Socket => e
    Rails.logger.error e
    []
  end
end