don't store local node info in db
This commit is contained in:
parent
fe9b0618ed
commit
5a8e08b2c2
5 changed files with 21 additions and 28 deletions
|
@ -486,9 +486,6 @@ class Nodes(Thread):
|
|||
self._q = Queue()
|
||||
with db.session():
|
||||
for u in user.models.User.query.filter_by(peered=True):
|
||||
if 'local' in u.info:
|
||||
del u.info['local']
|
||||
u.save()
|
||||
self.queue('add', u.id)
|
||||
get_peer(u.id)
|
||||
for u in user.models.User.query.filter_by(queued=True):
|
||||
|
|
|
@ -95,4 +95,4 @@ FULLTEXT_SUPPORT = fulltext.platform_supported()
|
|||
if not FULLTEXT_SUPPORT:
|
||||
config['itemKeys'] = [k for k in config['itemKeys'] if k['id'] != 'fulltext']
|
||||
|
||||
DB_VERSION = 14
|
||||
DB_VERSION = 15
|
||||
|
|
|
@ -15,7 +15,6 @@ shutdown = False
|
|||
websockets = []
|
||||
uisockets = []
|
||||
peers = {}
|
||||
|
||||
changelog_size = None
|
||||
|
||||
activity = {}
|
||||
|
|
|
@ -371,7 +371,9 @@ class Update(Thread):
|
|||
db_version = migrate_12()
|
||||
if db_version < 13:
|
||||
db_version = migrate_13()
|
||||
settings.server['db_version'] = settings.DB_VERSION
|
||||
if db_version < 15:
|
||||
db_version = migrate_15()
|
||||
settings.server['db_version'] = db_version
|
||||
|
||||
def run(self):
|
||||
self.status('Checking for updates...')
|
||||
|
@ -618,10 +620,14 @@ def migrate_13():
|
|||
settings.server['revision'] = revision
|
||||
return 13
|
||||
|
||||
def migrate_14():
|
||||
from user.models import List
|
||||
def migrate_15():
|
||||
from user.models import List, User
|
||||
with db.session():
|
||||
l = List.get(':Public')
|
||||
if l and not len(l.items):
|
||||
l.remove()
|
||||
return 14
|
||||
for u in User.query:
|
||||
if 'local' in u.info:
|
||||
del u.info['local']
|
||||
u.save()
|
||||
return 15
|
||||
|
|
|
@ -57,8 +57,7 @@ class User(db.Model):
|
|||
user = cls(id=id, peered=False, online=False)
|
||||
user.info = {}
|
||||
if state.nodes and state.nodes.local and id in state.nodes.local:
|
||||
user.info['local'] = state.nodes.local[id]
|
||||
user.info['username'] = user.info['local']['username']
|
||||
user.info['username'] = state.nodes.localo[id]['username']
|
||||
user.update_name()
|
||||
user.save()
|
||||
return user
|
||||
|
@ -84,6 +83,8 @@ class User(db.Model):
|
|||
j = {}
|
||||
if self.info:
|
||||
j.update(self.info)
|
||||
if state.nodes and self.id in state.nodes.local:
|
||||
j['local'] = state.nodes.local[self.id].copy()
|
||||
j['id'] = self.id
|
||||
if self.pending:
|
||||
j['pending'] = self.pending
|
||||
|
@ -603,25 +604,15 @@ def update_user_peering(user_id, peered, username=None):
|
|||
u.update_peering(peered, username)
|
||||
|
||||
def remove_local_info(id):
|
||||
with db.session():
|
||||
u = User.get(id, for_update=True)
|
||||
if u and 'local' in u.info:
|
||||
del u.info['local']
|
||||
u.save()
|
||||
u.trigger_status()
|
||||
if state.nodes:
|
||||
trigger_event('status', {
|
||||
'id': id,
|
||||
'online': state.nodes.is_online(id)
|
||||
})
|
||||
|
||||
def add_local_info(data):
|
||||
with db.session():
|
||||
u = User.get(data['id'], for_update=True)
|
||||
if u:
|
||||
if u.info['username'] != data['username']:
|
||||
u.info['username'] = data['username']
|
||||
u.update_name()
|
||||
u.info['local'] = data
|
||||
u.save()
|
||||
if state.nodes:
|
||||
state.nodes.queue('add', u.id)
|
||||
|
||||
state.nodes.queue('add', data['id'])
|
||||
|
||||
def upload(data):
|
||||
delay = 60
|
||||
|
|
Loading…
Reference in a new issue