pull changes in peer sort order, fixes #228

This commit is contained in:
j 2016-02-08 14:33:21 +05:30
parent 4549a4be4e
commit c82efdaff1
4 changed files with 22 additions and 12 deletions

View file

@ -339,11 +339,7 @@ class Item(db.Model):
if self.meta.get('sharemetadata'): if self.meta.get('sharemetadata'):
return return
peers = [u for u in self.users if u.id != settings.USER_ID] peers = [u for u in self.users if u.id != settings.USER_ID]
def peer_sort(u): peers.sort(key=lambda u: utils.user_sort_key(u.json()))
info = u.json()
return ox.sort_string(str(info.get('index', ''))
+ 'Z' + (info.get('name') or ''))
peers.sort(key=peer_sort)
sync_from = None sync_from = None
first_peer = None first_peer = None
# get first peer with sharemetadata set # get first peer with sharemetadata set

View file

@ -22,6 +22,7 @@ from changelog import Changelog
from websocket import trigger_event from websocket import trigger_event
from localnodes import LocalNodes from localnodes import LocalNodes
from tor_request import get_opener from tor_request import get_opener
from utils import user_sort_key
import state import state
import db import db
@ -474,7 +475,17 @@ class Nodes(Thread):
if state.activity and state.activity.get('activity') == 'import': if state.activity and state.activity.get('activity') == 'import':
return return
self._pulling = True self._pulling = True
for node in list(self._nodes.values()): users = []
with db.session():
from user.models import User
for u in User.query.filter(User.id!=settings.USER_ID).filter_by(peered=True).all():
users.append(u.json())
users.sort(key=user_sort_key)
for u in users:
if state.shutdown:
break
node = self._nodes.get(u['id'])
if node:
if not state.shutdown: if not state.shutdown:
node.online = node.can_connect() node.online = node.can_connect()
if not state.shutdown and node.online: if not state.shutdown and node.online:

View file

@ -10,7 +10,7 @@ import ox
from changelog import Changelog from changelog import Changelog
from oxtornado import actions from oxtornado import actions
from utils import update_dict from utils import update_dict, user_sort_key
from . import models from . import models
import settings import settings
import state import state
@ -132,7 +132,7 @@ def getUsers(data):
for n in users: for n in users:
n['local'] = n['id'] in local n['local'] = n['id'] in local
users.sort(key=lambda u: ox.sort_string(str(u.get('index', '')) + 'Z' + (u.get('name') or ''))) users.sort(key=user_sort_key)
return { return {
"users": users "users": users
} }

View file

@ -466,3 +466,6 @@ def ctl(*args):
else: else:
subprocess.Popen([os.path.join(settings.base_dir, 'ctl')] + list(args), subprocess.Popen([os.path.join(settings.base_dir, 'ctl')] + list(args),
close_fds=True, start_new_session=True) close_fds=True, start_new_session=True)
def user_sort_key(u):
return ox.sort_string(str(u.get('index', '')) + 'Z' + (u.get('name') or ''))