avoid extra lookup
This commit is contained in:
parent
1c2ef33353
commit
d7528f634f
2 changed files with 16 additions and 17 deletions
11
oml/nodes.py
11
oml/nodes.py
|
@ -445,15 +445,10 @@ class Nodes(Thread):
|
||||||
else:
|
else:
|
||||||
self._call(*args)
|
self._call(*args)
|
||||||
|
|
||||||
|
|
||||||
def cleanup(self):
|
def cleanup(self):
|
||||||
if not state.shutdown and self._local:
|
if not state.shutdown and self._local:
|
||||||
self._local.cleanup()
|
self._local.cleanup()
|
||||||
|
|
||||||
def pull(self):
|
|
||||||
if not self._pulling:
|
|
||||||
self.queue('pull')
|
|
||||||
|
|
||||||
def queue(self, *args):
|
def queue(self, *args):
|
||||||
self._q.put(list(args))
|
self._q.put(list(args))
|
||||||
|
|
||||||
|
@ -493,6 +488,10 @@ class Nodes(Thread):
|
||||||
if send_response:
|
if send_response:
|
||||||
self._nodes[user_id].send_response()
|
self._nodes[user_id].send_response()
|
||||||
|
|
||||||
|
def pull(self):
|
||||||
|
if not self._pulling:
|
||||||
|
self.queue('pull')
|
||||||
|
|
||||||
def _pull(self):
|
def _pull(self):
|
||||||
if state.activity and state.activity.get('activity') == 'import':
|
if state.activity and state.activity.get('activity') == 'import':
|
||||||
return
|
return
|
||||||
|
@ -503,7 +502,7 @@ class Nodes(Thread):
|
||||||
with db.session():
|
with db.session():
|
||||||
from user.models import User
|
from user.models import User
|
||||||
for u in User.query.filter(User.id!=settings.USER_ID).filter_by(peered=True).all():
|
for u in User.query.filter(User.id!=settings.USER_ID).filter_by(peered=True).all():
|
||||||
users.append(u.json())
|
users.append(u.json(['id', 'index', 'name']))
|
||||||
users.sort(key=user_sort_key)
|
users.sort(key=user_sort_key)
|
||||||
for u in users:
|
for u in users:
|
||||||
if state.shutdown:
|
if state.shutdown:
|
||||||
|
|
|
@ -86,18 +86,18 @@ class User(db.Model):
|
||||||
if self.pending:
|
if self.pending:
|
||||||
j['pending'] = self.pending
|
j['pending'] = self.pending
|
||||||
j['peered'] = self.peered
|
j['peered'] = self.peered
|
||||||
j['online'] = self.is_online()
|
if not keys or 'online' in keys:
|
||||||
j['nickname'] = self.info.get('nickname')
|
j['online'] = self.is_online()
|
||||||
j['username'] = self.info.get('username')
|
|
||||||
j['name'] = self.name
|
j['name'] = self.name
|
||||||
if self.id == settings.USER_ID:
|
if not keys or 'username' in keys or 'contact' in keys:
|
||||||
j['username'] = settings.preferences['username']
|
if self.id == settings.USER_ID:
|
||||||
j['contact'] = settings.preferences['contact']
|
j['username'] = settings.preferences['username']
|
||||||
elif self.id in state.peers:
|
j['contact'] = settings.preferences['contact']
|
||||||
peer = state.peers[self.id]
|
elif self.id in state.peers:
|
||||||
for key in ('username', 'contact'):
|
peer = state.peers[self.id]
|
||||||
if key in peer.info:
|
for key in ('username', 'contact'):
|
||||||
j[key] = peer.info[key]
|
if key in peer.info:
|
||||||
|
j[key] = peer.info[key]
|
||||||
if keys:
|
if keys:
|
||||||
for k in set(j) - set(keys):
|
for k in set(j) - set(keys):
|
||||||
del j[k]
|
del j[k]
|
||||||
|
|
Loading…
Reference in a new issue