remove peers outside of horizon
This commit is contained in:
parent
051db29cb0
commit
6ce76dfa9c
1 changed files with 20 additions and 0 deletions
|
@ -324,6 +324,7 @@ def sync_db():
|
|||
if commit:
|
||||
state.db.session.commit()
|
||||
cleanup_lists()
|
||||
cleanup_peers()
|
||||
|
||||
def cleanup_lists():
|
||||
import item.models
|
||||
|
@ -345,3 +346,22 @@ def cleanup_lists():
|
|||
|
||||
item.models.Item.remove_without_user()
|
||||
state.db.session.commit()
|
||||
|
||||
def cleanup_peers():
|
||||
import user.models
|
||||
other_peers = {}
|
||||
peers = [u for u in user.models.User.query.filter_by(peered=True)]
|
||||
peers.sort(key=lambda u: utils.user_sort_key(u.json()))
|
||||
known_peers = set()
|
||||
known_peers.add(settings.USER_ID)
|
||||
for u in peers:
|
||||
known_peers.add(u.id)
|
||||
peer = utils.get_peer(u.id)
|
||||
for id in peer.info.get('peers', {}):
|
||||
if id not in other_peers:
|
||||
other_peers[id] = peer.info['peers'][id]
|
||||
known_peers.add(id)
|
||||
for u in user.models.User.query.filter(user.models.User.id.notin_(list(known_peers))):
|
||||
if not 'local' in u.info and not u.pending:
|
||||
state.db.session.delete(u)
|
||||
state.db.session.commit()
|
||||
|
|
Loading…
Reference in a new issue