Browse Source

Adding common followers API, fixing fallback query again

master
Eugen Rochko 8 years ago
parent
commit
e0a197650a
9 changed files with 23 additions and 13 deletions
  1. +10
    -2
      app/controllers/api/v1/accounts_controller.rb
  2. +9
    -0
      app/models/account.rb
  3. +0
    -4
      app/models/follow_suggestion.rb
  4. +0
    -2
      app/views/api/v1/accounts/followers.rabl
  5. +0
    -2
      app/views/api/v1/accounts/following.rabl
  6. +2
    -0
      app/views/api/v1/accounts/index.rabl
  7. +1
    -1
      app/views/api/v1/accounts/statuses.rabl
  8. +0
    -2
      app/views/api/v1/accounts/suggestions.rabl
  9. +1
    -0
      config/routes.rb

+ 10
- 2
app/controllers/api/v1/accounts_controller.rb View File

@ -14,15 +14,23 @@ class Api::V1::AccountsController < ApiController
end
def following
@following = @account.following
@accounts = @account.following
render action: :index
end
def followers
@followers = @account.followers
@accounts = @account.followers
render action: :index
end
def common_followers
@accounts = @account.common_followers_with(current_user.account)
render action: :index
end
def suggestions
@accounts = FollowSuggestion.get(current_user.account_id)
render action: :index
end
def statuses

+ 9
- 0
app/models/account.rb 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

+ 0
- 4
app/models/follow_suggestion.rb View File

@ -36,11 +36,7 @@ END
neo = Neography::Rest.new
query = <<END
OPTIONAL MATCH (a {account_id: {id}})
WITH a
MATCH (b)
WHERE b <> a
AND NOT (a)-[:follows]->(b)
RETURN b.account_id
ORDER BY b.nodeRank DESC
LIMIT {limit}

+ 0
- 2
app/views/api/v1/accounts/followers.rabl View File

@ -1,2 +0,0 @@
collection @followers
extends('api/v1/accounts/show')

+ 0
- 2
app/views/api/v1/accounts/following.rabl View File

@ -1,2 +0,0 @@
collection @following
extends('api/v1/accounts/show')

+ 2
- 0
app/views/api/v1/accounts/index.rabl View File

@ -0,0 +1,2 @@
collection @accounts
extends 'api/v1/accounts/show'

+ 1
- 1
app/views/api/v1/accounts/statuses.rabl View File

@ -1,2 +1,2 @@
collection @statuses
extends('api/v1/statuses/show')
extends 'api/v1/statuses/show'

+ 0
- 2
app/views/api/v1/accounts/suggestions.rabl View File

@ -1,2 +0,0 @@
collection @accounts
extends('api/v1/accounts/show')

+ 1
- 0
config/routes.rb View File

@ -82,6 +82,7 @@ Rails.application.routes.draw do
get :statuses
get :followers
get :following
get :common_followers
post :follow
post :unfollow

Loading…
Cancel
Save