avoid tor deadlock, clenaup annotations on delete

This commit is contained in:
j 2019-02-16 13:26:31 +05:30
parent 6f8acb90d9
commit 8169d8e720
2 changed files with 15 additions and 3 deletions

View file

@ -311,13 +311,20 @@ class Item(db.Model):
def delete(self, commit=True): def delete(self, commit=True):
Sort.query.filter_by(item_id=self.id).delete() Sort.query.filter_by(item_id=self.id).delete()
Find.query.filter_by(item_id=self.id).delete()
if state.downloads and self.id in state.downloads.transfers: if state.downloads and self.id in state.downloads.transfers:
del state.downloads.transfers[self.id] del state.downloads.transfers[self.id]
state.db.session.delete(self) state.db.session.delete(self)
icons.clear('cover:%s' % self.id)
icons.clear('preview:%s' % self.id)
if commit: if commit:
state.db.session.commit() state.db.session.commit()
icons.clear('cover:%s' % self.id)
icons.clear('preview:%s' % self.id)
def remove_annotations(self):
from annotation.models import Annotation
for a in Annotation.query.filter_by(item_id=self.id, user_id=state.user()):
a.add_record('removeannotation')
a.delete()
meta_keys = ( meta_keys = (
'author', 'author',
@ -562,6 +569,7 @@ class Item(db.Model):
state.db.session.add(self) state.db.session.add(self)
def remove_file(self): def remove_file(self):
folders = set()
for f in self.files.all(): for f in self.files.all():
path = f.fullpath() path = f.fullpath()
if os.path.exists(path): if os.path.exists(path):
@ -569,10 +577,12 @@ class Item(db.Model):
try: try:
os.chmod(path, mode) os.chmod(path, mode)
os.unlink(path) os.unlink(path)
remove_empty_folders(os.path.dirname(path)) folders.add(os.path.dirname(path))
except: except:
pass pass
state.db.session.delete(f) state.db.session.delete(f)
for folder in folders:
remove_empty_folders(folder)
user = state.user() user = state.user()
if user in self.users: if user in self.users:
self.users.remove(user) self.users.remove(user)
@ -589,6 +599,7 @@ class Item(db.Model):
if self.id in state.downloads.transfers: if self.id in state.downloads.transfers:
del state.downloads.transfers[self.id] del state.downloads.transfers[self.id]
add_record('removeitem', self.id) add_record('removeitem', self.id)
self.remove_annotations()
class Sort(db.Model): class Sort(db.Model):
__tablename__ = 'sort' __tablename__ = 'sort'

View file

@ -103,6 +103,7 @@ DirReqStatistics 0
for line in self.p.stdout: for line in self.p.stdout:
self._status.append(line) self._status.append(line)
logger.debug(line) logger.debug(line)
self.p.communicate()
time.sleep(0.5) time.sleep(0.5)
self.p = None self.p = None