cleanup in progress apply_changes on peer removal

This commit is contained in:
j 2016-01-14 19:06:07 +05:30
parent ec50a04097
commit 8e3d8b5f8e
3 changed files with 19 additions and 8 deletions

View file

@ -82,6 +82,10 @@ class Changelog(db.Model):
def apply_changes(cls, user, changes):
trigger = changes
for change in changes:
if user.id in state.removepeer:
user.cleanup()
del state.removepeer[user.id]
return False
if not cls.apply_change(user, change, trigger=False):
logger.debug('FAIL %s', change)
trigger = False

View file

@ -12,6 +12,7 @@ update = False
websockets = []
activity = {}
removepeer = {}
def user():
import settings

View file

@ -113,25 +113,31 @@ class User(db.Model):
Changelog.record(state.user(), 'addpeer', self.id, self.nickname)
self.peered = True
self.save()
if self.id in state.removepeer:
del state.removepeer[self.id]
else:
self.pending = ''
self.peered = False
self.queued = False
self.update_name()
self.save()
List.query.filter_by(user_id=self.id).delete()
for i in self.items:
i.users.remove(self)
if not i.users:
i.delete()
Changelog.query.filter_by(user_id=self.id).delete()
Metadata.query.filter_by(user_id=self.id).delete()
if self.name in settings.ui['showFolder']:
del settings.ui['showFolder'][self.name]
settings.ui._save()
self.save()
self.cleanup()
if was_peering:
Changelog.record(state.user(), 'removepeer', self.id)
state.removepeer[self.id] = True
self.save()
def cleanup(self):
List.query.filter_by(user_id=self.id).delete()
for i in self.items:
i.users.remove(self)
if not i.users:
i.delete()
Changelog.query.filter_by(user_id=self.id).delete()
Metadata.query.filter_by(user_id=self.id).delete()
self.save()
def update_name(self):