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'):
return
peers = [u for u in self.users if u.id != settings.USER_ID]
def peer_sort(u):
info = u.json()
return ox.sort_string(str(info.get('index', ''))
+ 'Z' + (info.get('name') or ''))
peers.sort(key=peer_sort)
peers.sort(key=lambda u: utils.user_sort_key(u.json()))
sync_from = None
first_peer = None
# get first peer with sharemetadata set

View File

@ -22,6 +22,7 @@ from changelog import Changelog
from websocket import trigger_event
from localnodes import LocalNodes
from tor_request import get_opener
from utils import user_sort_key
import state
import db
@ -474,11 +475,21 @@ class Nodes(Thread):
if state.activity and state.activity.get('activity') == 'import':
return
self._pulling = True
for node in list(self._nodes.values()):
if not state.shutdown:
node.online = node.can_connect()
if not state.shutdown and node.online:
node.pullChanges()
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:
node.online = node.can_connect()
if not state.shutdown and node.online:
node.pullChanges()
self._pulling = False
def run(self):

View File

@ -10,7 +10,7 @@ import ox
from changelog import Changelog
from oxtornado import actions
from utils import update_dict
from utils import update_dict, user_sort_key
from . import models
import settings
import state
@ -132,7 +132,7 @@ def getUsers(data):
for n in users:
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 {
"users": users
}

View File

@ -466,3 +466,6 @@ def ctl(*args):
else:
subprocess.Popen([os.path.join(settings.base_dir, 'ctl')] + list(args),
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 ''))