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:
|
||||
self._call(*args)
|
||||
|
||||
|
||||
def cleanup(self):
|
||||
if not state.shutdown and self._local:
|
||||
self._local.cleanup()
|
||||
|
||||
def pull(self):
|
||||
if not self._pulling:
|
||||
self.queue('pull')
|
||||
|
||||
def queue(self, *args):
|
||||
self._q.put(list(args))
|
||||
|
||||
|
@ -493,6 +488,10 @@ class Nodes(Thread):
|
|||
if send_response:
|
||||
self._nodes[user_id].send_response()
|
||||
|
||||
def pull(self):
|
||||
if not self._pulling:
|
||||
self.queue('pull')
|
||||
|
||||
def _pull(self):
|
||||
if state.activity and state.activity.get('activity') == 'import':
|
||||
return
|
||||
|
@ -503,7 +502,7 @@ class Nodes(Thread):
|
|||
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.append(u.json(['id', 'index', 'name']))
|
||||
users.sort(key=user_sort_key)
|
||||
for u in users:
|
||||
if state.shutdown:
|
||||
|
|
|
@ -86,18 +86,18 @@ class User(db.Model):
|
|||
if self.pending:
|
||||
j['pending'] = self.pending
|
||||
j['peered'] = self.peered
|
||||
j['online'] = self.is_online()
|
||||
j['nickname'] = self.info.get('nickname')
|
||||
j['username'] = self.info.get('username')
|
||||
if not keys or 'online' in keys:
|
||||
j['online'] = self.is_online()
|
||||
j['name'] = self.name
|
||||
if self.id == settings.USER_ID:
|
||||
j['username'] = settings.preferences['username']
|
||||
j['contact'] = settings.preferences['contact']
|
||||
elif self.id in state.peers:
|
||||
peer = state.peers[self.id]
|
||||
for key in ('username', 'contact'):
|
||||
if key in peer.info:
|
||||
j[key] = peer.info[key]
|
||||
if not keys or 'username' in keys or 'contact' in keys:
|
||||
if self.id == settings.USER_ID:
|
||||
j['username'] = settings.preferences['username']
|
||||
j['contact'] = settings.preferences['contact']
|
||||
elif self.id in state.peers:
|
||||
peer = state.peers[self.id]
|
||||
for key in ('username', 'contact'):
|
||||
if key in peer.info:
|
||||
j[key] = peer.info[key]
|
||||
if keys:
|
||||
for k in set(j) - set(keys):
|
||||
del j[k]
|
||||
|
|
Loading…
Reference in a new issue