Compare commits

...

5 commits

Author SHA1 Message Date
j
9344b84d86 remove double peering issues 2019-01-19 16:40:06 +05:30
j
1adbcc3d0b broadcast name changes 2019-01-19 16:11:05 +05:30
j
038b04c178 add debugging 2019-01-19 14:37:15 +05:30
j
98bd2f6cf3 dont query for empty list 2019-01-19 14:22:08 +05:30
j
3a8429b9ac append to listorder 2019-01-19 13:59:35 +05:30
6 changed files with 29 additions and 34 deletions

View file

@ -44,6 +44,11 @@ class Peer(object):
self.info['peers'] = {}
if 'lists' not in self.info:
self.info['lists'] = {}
for name in self.info['lists']:
if 'listorder' not in self.info:
self.info['listorder'] = []
if name not in self.info['listorder']:
self.info['listorder'].append(name)
def apply_log(self):
changes = []
@ -113,6 +118,10 @@ class Peer(object):
query = args[1]
if name not in self.info['lists']:
self.info['lists'][name] = []
if 'listorder' not in self.info:
self.info['listorder'] = []
if name not in self.info['listorder']:
self.info['listorder'].append(name)
elif action == 'editlist':
name, new = args
if name in self.info['lists']:

View file

@ -84,6 +84,7 @@ def api_upload(user_id, items):
if peer:
l = List.get_or_create(':Public')
if l:
logger.debug('%s added items to public folder: %s', user_id, items)
l.add_items(items)
return True
return False

View file

@ -462,6 +462,7 @@ class Node(Thread):
return False
def upload(self, items):
logger.debug('add items to %s\'s public folder: %s', self.id, items)
r = self.request('upload', items)
return bool(r)

View file

@ -107,33 +107,16 @@ class Parser(object):
vk = getattr(self._sort, k)
q = operators.eq(vk, v)
ids = self._model.query.join(self._sort).filter(q).options(load_only('id'))
if not ids:
q = operators.eq(self._model.id, '')
if exclude:
q = ~q
else:
in_op = operators.notin_op if exclude else operators.in_op
q = in_op(self._model.id, ids)
return q
return self.in_ids(ids, exclude)
elif k == 'id':
if op == '&':
ids = v
else:
ids = [v]
in_op = operators.notin_op if exclude else operators.in_op
q = in_op(self._model.id, ids)
return q
return self.in_ids(ids, exclude)
elif k == 'fulltext':
ids = find_fulltext(v)
if ids:
in_op = operators.notin_op if exclude else operators.in_op
q = in_op(self._model.id, ids)
else:
# nothing
q = operators.eq(self._model.id, -1)
if exclude:
q = ~q
return q
return self.in_ids(ids, exclude)
elif key_type in ("string", "text"):
if isinstance(v, str):
@ -142,9 +125,7 @@ class Parser(object):
if k != '*':
q &= (self._find.key == k)
ids = self._model.query.join(self._find).filter(q).options(load_only('id'))
in_op = operators.notin_op if exclude else operators.in_op
q = in_op(self._model.id, ids)
return q
return self.in_ids(ids, exclude)
elif k == 'list':
nickname, name = v.split(':', 1)
if nickname:
@ -175,9 +156,7 @@ class Parser(object):
)
else:
ids = l.get_items().options(load_only('id'))
in_op = operators.notin_op if exclude else operators.in_op
q = in_op(self._model.id, ids)
return q
return self.in_ids(ids, exclude)
elif key_type == 'date':
def parse_date(d):
while len(d) < 3:
@ -188,15 +167,21 @@ class Parser(object):
vk = getattr(self._sort, k)
q = get_operator(op, 'int')(vk, v)
ids = self._model.query.join(self._find).filter(q).options(load_only('id'))
in_op = operators.notin_op if exclude else operators.in_op
q = in_op(self._model.id, ids)
return q
return self.in_ids(ids, exclude)
else: #integer, float, time
q = get_operator(op, 'int')(getattr(self._sort, k), v)
ids = self._model.query.join(self._find).filter(q).options(load_only('id'))
return self.in_ids(ids, exclude)
def in_ids(self, ids, exclude):
if isinstance(ids, list) and not ids:
q = operators.eq(self._model.id, '')
if exclude:
q = ~q
else:
in_op = operators.notin_op if exclude else operators.in_op
q = in_op(self._model.id, ids)
return q
return q
def parse_conditions(self, conditions, operator):
'''

View file

@ -97,6 +97,8 @@ def setPreferences(data):
u.save()
if change_username:
add_record('editusername', data['username'])
if state.nodes and state.nodes.local:
state.nodes.local._update_if_ip_changed()
if change_contact:
add_record('editcontact', data['contact'])
if change_path:

View file

@ -154,15 +154,12 @@ class User(db.Model):
if username:
self.info['username'] = username
self.update_name()
# FIXME: need to set peered to False to not trigger changelog event
# before other side receives acceptPeering request
self.peered = False
self.save()
if not was_peering:
add_record('addpeer', self.id, self.nickname)
if 'index' not in self.info:
self.info['index'] = max([
u.info.get('index', -1) for u in User.query.filter_by(peered=True)
if u.id != self.id
] + [0]) + 1
self.peered = True
self.save()