Browse Source

Remove Neo4J

closed-social-v3
Eugen Rochko 8 years ago
parent
commit
8efa081f21
23 changed files with 6 additions and 323 deletions
  1. +0
    -0
      Dockerfile
  2. +0
    -17
      Dockerfile.neo4j
  3. +0
    -1
      Gemfile
  4. +0
    -11
      Gemfile.lock
  5. +0
    -37
      app/assets/javascripts/components/actions/suggestions.jsx
  6. +0
    -86
      app/assets/javascripts/components/features/compose/components/suggestions_box.jsx
  7. +0
    -8
      app/assets/javascripts/components/features/compose/containers/suggestions_container.jsx
  8. +4
    -11
      app/assets/javascripts/components/features/compose/index.jsx
  9. +0
    -2
      app/assets/javascripts/components/locales/de.jsx
  10. +0
    -2
      app/assets/javascripts/components/locales/en.jsx
  11. +0
    -2
      app/assets/javascripts/components/locales/es.jsx
  12. +0
    -2
      app/assets/javascripts/components/locales/fr.jsx
  13. +0
    -2
      app/assets/javascripts/components/locales/pt.jsx
  14. +0
    -4
      app/assets/javascripts/components/reducers/user_lists.jsx
  15. +0
    -10
      app/controllers/api/v1/accounts_controller.rb
  16. +0
    -9
      app/models/account.rb
  17. +0
    -28
      app/models/follow.rb
  18. +0
    -50
      app/models/follow_suggestion.rb
  19. +0
    -5
      config/initializers/neography.rb
  20. +0
    -2
      config/routes.rb
  21. +2
    -13
      docker-compose.yml
  22. +0
    -7
      lib/tasks/mastodon.rake
  23. +0
    -14
      spec/controllers/api/v1/accounts_controller_spec.rb

Dockerfile.app → Dockerfile View File


+ 0
- 17
Dockerfile.neo4j View File

@ -1,17 +0,0 @@
FROM neo4j:latest
ENV NEO4J_AUTH=none
RUN cd /var/lib/neo4j/plugins \
&& wget http://products.graphaware.com/download/framework-server-community/graphaware-server-community-all-3.0.6.43.jar \
&& wget http://products.graphaware.com/download/noderank/graphaware-noderank-3.0.6.43.3.jar
RUN echo "dbms.unmanaged_extension_classes=com.graphaware.server=/graphaware" >> /var/lib/neo4j/conf/neo4j.conf
RUN echo 'com.graphaware.runtime.enabled=true\n\
com.graphaware.module.NR.1=com.graphaware.module.noderank.NodeRankModuleBootstrapper\n\
com.graphaware.module.NR.maxTopRankNodes=10\n\
com.graphaware.module.NR.dampingFactor=0.85\n\
com.graphaware.module.NR.propertyKey=nodeRank\n'\
>> /var/lib/neo4j/conf/neo4j.conf
RUN echo 'com.graphaware.runtime.stats.disabled=true\n\
com.graphaware.server.stats.disabled=true\n'\
>> /var/lib/neo4j/conf/neo4j.conf

+ 0
- 1
Gemfile View File

@ -43,7 +43,6 @@ gem 'rack-attack'
gem 'rack-cors', require: 'rack/cors' gem 'rack-cors', require: 'rack/cors'
gem 'sidekiq' gem 'sidekiq'
gem 'ledermann-rails-settings' gem 'ledermann-rails-settings'
gem 'neography'
gem 'pg_search' gem 'pg_search'
gem 'react-rails' gem 'react-rails'

+ 0
- 11
Gemfile.lock View File

@ -132,7 +132,6 @@ GEM
thread thread
thread_safe thread_safe
erubis (2.7.0) erubis (2.7.0)
excon (0.53.0)
execjs (2.7.0) execjs (2.7.0)
fabrication (2.15.2) fabrication (2.15.2)
fast_blank (1.0.0) fast_blank (1.0.0)
@ -213,19 +212,11 @@ GEM
mini_portile2 (2.1.0) mini_portile2 (2.1.0)
minitest (5.9.1) minitest (5.9.1)
multi_json (1.12.1) multi_json (1.12.1)
neography (1.8.0)
excon (>= 0.33.0)
json (>= 1.7.7)
multi_json (>= 1.3.2)
os (>= 0.9.6)
rake (>= 0.8.7)
rubyzip (>= 1.0.0)
nio4r (1.2.1) nio4r (1.2.1)
nokogiri (1.6.8.1) nokogiri (1.6.8.1)
mini_portile2 (~> 2.1.0) mini_portile2 (~> 2.1.0)
oj (2.17.3) oj (2.17.3)
orm_adapter (0.5.0) orm_adapter (0.5.0)
os (0.9.6)
ostatus2 (1.0.2) ostatus2 (1.0.2)
addressable (~> 2.4) addressable (~> 2.4)
http (~> 2.0) http (~> 2.0)
@ -339,7 +330,6 @@ GEM
ruby-progressbar (~> 1.7) ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1) unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.8.1) ruby-progressbar (1.8.1)
rubyzip (1.2.0)
safe_yaml (1.0.4) safe_yaml (1.0.4)
sass (3.4.22) sass (3.4.22)
sass-rails (5.0.6) sass-rails (5.0.6)
@ -435,7 +425,6 @@ DEPENDENCIES
letter_opener letter_opener
link_header link_header
lograge lograge
neography
nokogiri nokogiri
oj oj
ostatus2 ostatus2

+ 0
- 37
app/assets/javascripts/components/actions/suggestions.jsx View File

@ -1,37 +0,0 @@
import api from '../api';
export const SUGGESTIONS_FETCH_REQUEST = 'SUGGESTIONS_FETCH_REQUEST';
export const SUGGESTIONS_FETCH_SUCCESS = 'SUGGESTIONS_FETCH_SUCCESS';
export const SUGGESTIONS_FETCH_FAIL = 'SUGGESTIONS_FETCH_FAIL';
export function fetchSuggestions() {
return (dispatch, getState) => {
dispatch(fetchSuggestionsRequest());
api(getState).get('/api/v1/accounts/suggestions').then(response => {
dispatch(fetchSuggestionsSuccess(response.data));
}).catch(error => {
dispatch(fetchSuggestionsFail(error));
});
};
};
export function fetchSuggestionsRequest() {
return {
type: SUGGESTIONS_FETCH_REQUEST
};
};
export function fetchSuggestionsSuccess(accounts) {
return {
type: SUGGESTIONS_FETCH_SUCCESS,
accounts: accounts
};
};
export function fetchSuggestionsFail(error) {
return {
type: SUGGESTIONS_FETCH_FAIL,
error: error
};
};

+ 0
- 86
app/assets/javascripts/components/features/compose/components/suggestions_box.jsx View File

@ -1,86 +0,0 @@
import PureRenderMixin from 'react-addons-pure-render-mixin';
import ImmutablePropTypes from 'react-immutable-proptypes';
import AccountContainer from '../../../containers/account_container';
import { FormattedMessage } from 'react-intl';
const outerStyle = {
position: 'relative'
};
const headerStyle = {
fontSize: '14px',
fontWeight: '500',
display: 'block',
padding: '10px',
color: '#9baec8',
background: '#454b5e',
overflow: 'hidden'
};
const nextStyle = {
display: 'inline-block',
float: 'right',
fontWeight: '400',
color: '#2b90d9'
};
const SuggestionsBox = React.createClass({
propTypes: {
accountIds: ImmutablePropTypes.list,
perWindow: React.PropTypes.number
},
getInitialState () {
return {
index: 0
};
},
getDefaultProps () {
return {
perWindow: 2
};
},
mixins: [PureRenderMixin],
handleNextClick (e) {
e.preventDefault();
let newIndex = this.state.index + 1;
if (this.props.accountIds.skip(this.props.perWindow * newIndex).size === 0) {
newIndex = 0;
}
this.setState({ index: newIndex });
},
render () {
const { accountIds, perWindow } = this.props;
if (!accountIds || accountIds.size === 0) {
return <div />;
}
let nextLink = '';
if (accountIds.size > perWindow) {
nextLink = <a href='#' style={nextStyle} onClick={this.handleNextClick}><FormattedMessage id='suggestions_box.refresh' defaultMessage='Refresh' /></a>;
}
return (
<div style={outerStyle}>
<strong style={headerStyle}>
<FormattedMessage id='suggestions_box.who_to_follow' defaultMessage='Who to follow' /> {nextLink}
</strong>
{accountIds.skip(perWindow * this.state.index).take(perWindow).map(accountId => <AccountContainer key={accountId} id={accountId} withNote={false} />)}
</div>
);
}
});
export default SuggestionsBox;

+ 0
- 8
app/assets/javascripts/components/features/compose/containers/suggestions_container.jsx View File

@ -1,8 +0,0 @@
import { connect } from 'react-redux';
import SuggestionsBox from '../components/suggestions_box';
const mapStateToProps = (state) => ({
accountIds: state.getIn(['user_lists', 'suggestions'])
});
export default connect(mapStateToProps)(SuggestionsBox);

+ 4
- 11
app/assets/javascripts/components/features/compose/index.jsx View File

@ -3,9 +3,7 @@ import ComposeFormContainer from './containers/compose_form_container';
import UploadFormContainer from './containers/upload_form_container'; import UploadFormContainer from './containers/upload_form_container';
import NavigationContainer from './containers/navigation_container'; import NavigationContainer from './containers/navigation_container';
import PureRenderMixin from 'react-addons-pure-render-mixin'; import PureRenderMixin from 'react-addons-pure-render-mixin';
import SuggestionsContainer from './containers/suggestions_container';
import SearchContainer from './containers/search_container'; import SearchContainer from './containers/search_container';
import { fetchSuggestions } from '../../actions/suggestions';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { mountCompose, unmountCompose } from '../../actions/compose'; import { mountCompose, unmountCompose } from '../../actions/compose';
@ -19,7 +17,6 @@ const Compose = React.createClass({
componentDidMount () { componentDidMount () {
this.props.dispatch(mountCompose()); this.props.dispatch(mountCompose());
this.props.dispatch(fetchSuggestions());
}, },
componentWillUnmount () { componentWillUnmount () {
@ -29,14 +26,10 @@ const Compose = React.createClass({
render () { render () {
return ( return (
<Drawer> <Drawer>
<div style={{ flex: '1 1 auto' }}>
<SearchContainer />
<NavigationContainer />
<ComposeFormContainer />
<UploadFormContainer />
</div>
<SuggestionsContainer />
<SearchContainer />
<NavigationContainer />
<ComposeFormContainer />
<UploadFormContainer />
</Drawer> </Drawer>
); );
} }

+ 0
- 2
app/assets/javascripts/components/locales/de.jsx View File

@ -41,8 +41,6 @@ const en = {
"search.placeholder": "Suche", "search.placeholder": "Suche",
"search.account": "Konto", "search.account": "Konto",
"search.hashtag": "Hashtag", "search.hashtag": "Hashtag",
"suggestions_box.who_to_follow": "Wem folgen",
"suggestions_box.refresh": "Aktualisieren",
"upload_button.label": "Media-Datei anfügen", "upload_button.label": "Media-Datei anfügen",
"upload_form.undo": "Entfernen", "upload_form.undo": "Entfernen",
"notification.follow": "{name} folgt dir", "notification.follow": "{name} folgt dir",

+ 0
- 2
app/assets/javascripts/components/locales/en.jsx View File

@ -45,8 +45,6 @@ const en = {
"search.placeholder": "Search", "search.placeholder": "Search",
"search.account": "Account", "search.account": "Account",
"search.hashtag": "Hashtag", "search.hashtag": "Hashtag",
"suggestions_box.who_to_follow": "Who to follow",
"suggestions_box.refresh": "Refresh",
"upload_button.label": "Add media", "upload_button.label": "Add media",
"upload_form.undo": "Undo", "upload_form.undo": "Undo",
"notification.follow": "{name} followed you", "notification.follow": "{name} followed you",

+ 0
- 2
app/assets/javascripts/components/locales/es.jsx View File

@ -42,8 +42,6 @@ const es = {
"search.placeholder": "Buscar", "search.placeholder": "Buscar",
"search.account": "Cuenta", "search.account": "Cuenta",
"search.hashtag": "Etiqueta", "search.hashtag": "Etiqueta",
"suggestions_box.who_to_follow": "A quién seguir",
"suggestions_box.refresh": "Refrescar",
"upload_button.label": "Añadir medio", "upload_button.label": "Añadir medio",
"upload_form.undo": "Deshacer", "upload_form.undo": "Deshacer",
"notification.follow": "{name} le esta ahora siguiendo", "notification.follow": "{name} le esta ahora siguiendo",

+ 0
- 2
app/assets/javascripts/components/locales/fr.jsx View File

@ -41,8 +41,6 @@ const fr = {
"search.placeholder": "Chercher", "search.placeholder": "Chercher",
"search.account": "Compte", "search.account": "Compte",
"search.hashtag": "Mot-clé", "search.hashtag": "Mot-clé",
"suggestions_box.who_to_follow": "Suggestions",
"suggestions_box.refresh": "Rafraîchir",
"upload_button.label": "Joindre un média", "upload_button.label": "Joindre un média",
"upload_form.undo": "Annuler", "upload_form.undo": "Annuler",
"notification.follow": "{name} s’est abonné⋅e à vos statuts", "notification.follow": "{name} s’est abonné⋅e à vos statuts",

+ 0
- 2
app/assets/javascripts/components/locales/pt.jsx View File

@ -40,8 +40,6 @@ const pt = {
"search.placeholder": "Busca", "search.placeholder": "Busca",
"search.account": "Conta", "search.account": "Conta",
"search.hashtag": "Hashtag", "search.hashtag": "Hashtag",
"suggestions_box.who_to_follow": "Quem seguir",
"suggestions_box.refresh": "Recarregar",
"upload_button.label": "Adicionar media", "upload_button.label": "Adicionar media",
"upload_form.undo": "Desfazer" "upload_form.undo": "Desfazer"
}; };

+ 0
- 4
app/assets/javascripts/components/reducers/user_lists.jsx View File

@ -4,7 +4,6 @@ import {
FOLLOWING_FETCH_SUCCESS, FOLLOWING_FETCH_SUCCESS,
FOLLOWING_EXPAND_SUCCESS FOLLOWING_EXPAND_SUCCESS
} from '../actions/accounts'; } from '../actions/accounts';
import { SUGGESTIONS_FETCH_SUCCESS } from '../actions/suggestions';
import { import {
REBLOGS_FETCH_SUCCESS, REBLOGS_FETCH_SUCCESS,
FAVOURITES_FETCH_SUCCESS FAVOURITES_FETCH_SUCCESS
@ -14,7 +13,6 @@ import Immutable from 'immutable';
const initialState = Immutable.Map({ const initialState = Immutable.Map({
followers: Immutable.Map(), followers: Immutable.Map(),
following: Immutable.Map(), following: Immutable.Map(),
suggestions: Immutable.List(),
reblogged_by: Immutable.Map(), reblogged_by: Immutable.Map(),
favourited_by: Immutable.Map() favourited_by: Immutable.Map()
}); });
@ -42,8 +40,6 @@ export default function userLists(state = initialState, action) {
return normalizeList(state, 'following', action.id, action.accounts, action.next); return normalizeList(state, 'following', action.id, action.accounts, action.next);
case FOLLOWING_EXPAND_SUCCESS: case FOLLOWING_EXPAND_SUCCESS:
return appendToList(state, 'following', action.id, action.accounts, action.next); return appendToList(state, 'following', action.id, action.accounts, action.next);
case SUGGESTIONS_FETCH_SUCCESS:
return state.set('suggestions', Immutable.List(action.accounts.map(item => item.id)));
case REBLOGS_FETCH_SUCCESS: case REBLOGS_FETCH_SUCCESS:
return state.setIn(['reblogged_by', action.id], Immutable.List(action.accounts.map(item => item.id))); return state.setIn(['reblogged_by', action.id], Immutable.List(action.accounts.map(item => item.id)));
case FAVOURITES_FETCH_SUCCESS: case FAVOURITES_FETCH_SUCCESS:

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

@ -46,16 +46,6 @@ class Api::V1::AccountsController < ApiController
render action: :index render action: :index
end 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 def statuses
@statuses = @account.statuses.paginate_by_max_id(DEFAULT_STATUSES_LIMIT, params[:max_id], params[:since_id]).to_a @statuses = @account.statuses.paginate_by_max_id(DEFAULT_STATUSES_LIMIT, params[:max_id], params[:since_id]).to_a
@statuses = cache(@statuses) @statuses = cache(@statuses)

+ 0
- 9
app/models/account.rb View File

@ -130,15 +130,6 @@ class Account < ApplicationRecord
username username
end 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 = Account.where(id: ids).with_counters.limit(20).map { |a| [a.id, a] }.to_h
ids.map { |id| accounts[id] }.compact
rescue Neography::NeographyError, Excon::Error::Socket
[]
end
class << self class << self
def find_local!(username) def find_local!(username)
find_remote!(username, nil) find_remote!(username, nil)

+ 0
- 28
app/models/follow.rb View File

@ -27,32 +27,4 @@ class Follow < ApplicationRecord
def title def title
destroyed? ? "#{account.acct} is no longer following #{target_account.acct}" : "#{account.acct} started following #{target_account.acct}" destroyed? ? "#{account.acct} is no longer following #{target_account.acct}" : "#{account.acct} started following #{target_account.acct}"
end end
after_create :add_to_graph
after_destroy :remove_from_graph
def sync!
add_to_graph
end
private
def add_to_graph
neo = Neography::Rest.new
a = neo.create_unique_node('account_index', 'Account', account_id.to_s, account_id: account_id)
b = neo.create_unique_node('account_index', 'Account', target_account_id.to_s, account_id: target_account_id)
neo.create_unique_relationship('follow_index', 'Follow', id.to_s, 'follows', a, b)
rescue Neography::NeographyError, Excon::Error::Socket => e
Rails.logger.error e
end
def remove_from_graph
neo = Neography::Rest.new
rel = neo.get_relationship_index('follow_index', 'Follow', id.to_s)
neo.delete_relationship(rel)
rescue Neography::NeographyError, Excon::Error::Socket => e
Rails.logger.error e
end
end end

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

@ -1,50 +0,0 @@
# frozen_string_literal: true
class FollowSuggestion
class << self
def get(for_account_id, limit = 10)
neo = Neography::Rest.new
query = <<END
MATCH (a {account_id: {id}})-[:follows]->(b)-[:follows]->(c)
WHERE a <> c
AND NOT (a)-[:follows]->(c)
RETURN DISTINCT c.account_id, count(b), c.nodeRank
ORDER BY count(b) DESC, c.nodeRank DESC
LIMIT {limit}
END
results = neo.execute_query(query, id: for_account_id, limit: limit)
if results.empty? || results['data'].empty?
results = fallback(for_account_id, limit)
elsif results['data'].size < limit
results['data'] = (results['data'] + fallback(for_account_id, limit - results['data'].size)['data']).uniq
end
account_ids = results['data'].map(&:first)
blocked_ids = Block.where(account_id: for_account_id).pluck(:target_account_id)
accounts_map = Account.where(id: account_ids - blocked_ids).with_counters.map { |a| [a.id, a] }.to_h
account_ids.map { |id| accounts_map[id] }.compact
rescue Neography::NeographyError, Excon::Error::Socket => e
Rails.logger.error e
return []
end
private
def fallback(for_account_id, limit)
neo = Neography::Rest.new
query = <<END
MATCH (b)
RETURN b.account_id
ORDER BY b.nodeRank DESC
LIMIT {limit}
END
neo.execute_query(query, id: for_account_id, limit: limit)
end
end
end

+ 0
- 5
config/initializers/neography.rb View File

@ -1,5 +0,0 @@
Neography.configure do |config|
config.protocol = "http"
config.server = ENV.fetch('NEO4J_HOST') { 'localhost' }
config.port = ENV.fetch('NEO4J_PORT') { 7474 }
end

+ 0
- 2
config/routes.rb View File

@ -80,7 +80,6 @@ Rails.application.routes.draw do
collection do collection do
get :relationships get :relationships
get :verify_credentials get :verify_credentials
get :suggestions
get :search get :search
end end
@ -88,7 +87,6 @@ Rails.application.routes.draw do
get :statuses get :statuses
get :followers get :followers
get :following get :following
get :common_followers
post :follow post :follow
post :unfollow post :unfollow

+ 2
- 13
docker-compose.yml View File

@ -6,16 +6,9 @@ services:
redis: redis:
restart: always restart: always
image: redis image: redis
neo4j:
restart: always
build:
context: .
dockerfile: Dockerfile.neo4j
web: web:
restart: always restart: always
build:
context: .
dockerfile: Dockerfile.app
build: .
env_file: .env.production env_file: .env.production
command: bundle exec rails s -p 3000 -b '0.0.0.0' command: bundle exec rails s -p 3000 -b '0.0.0.0'
ports: ports:
@ -23,20 +16,16 @@ services:
depends_on: depends_on:
- db - db
- redis - redis
- neo4j
volumes: volumes:
- ./public/assets:/mastodon/public/assets - ./public/assets:/mastodon/public/assets
- ./public/system:/mastodon/public/system - ./public/system:/mastodon/public/system
sidekiq: sidekiq:
restart: always restart: always
build:
context: .
dockerfile: Dockerfile.app
build: .
env_file: .env.production env_file: .env.production
command: bundle exec sidekiq -q default -q mailers command: bundle exec sidekiq -q default -q mailers
depends_on: depends_on:
- db - db
- redis - redis
- neo4j
volumes: volumes:
- ./public/system:/mastodon/public/system - ./public/system:/mastodon/public/system

+ 0
- 7
lib/tasks/mastodon.rake View File

@ -49,11 +49,4 @@ namespace :mastodon do
Redis.current.keys('feed:*').each { |key| Redis.current.del(key) } Redis.current.keys('feed:*').each { |key| Redis.current.del(key) }
end end
end end
namespace :graphs do
desc 'Syncs all follow relationships to Neo4J'
task sync: :environment do
Follow.find_each(&:sync!)
end
end
end end

+ 0
- 14
spec/controllers/api/v1/accounts_controller_spec.rb View File

@ -46,20 +46,6 @@ RSpec.describe Api::V1::AccountsController, type: :controller do
end end
end end
describe 'GET #suggestions' do
it 'returns http success' do
get :suggestions
expect(response).to have_http_status(:success)
end
end
describe 'GET #common_followers' do
it 'returns http success' do
get :common_followers, params: { id: user.account.id }
expect(response).to have_http_status(:success)
end
end
describe 'POST #follow' do describe 'POST #follow' do
let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account } let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }

Loading…
Cancel
Save