Task remove optimization

This commit is contained in:
shortcutme 2019-12-31 12:50:21 +01:00
parent 721d4a22f1
commit ba218974c4
No known key found for this signature in database
GPG Key ID: 5B63BAE6CB9613AE
1 changed files with 10 additions and 4 deletions

View File

@ -98,6 +98,11 @@ class WorkerTaskManager(CustomSortedList):
def __contains__(self, value):
return value["inner_path"] in self.inner_paths
def __delitem__(self, index):
# Remove from inner path cache
del self.inner_paths[self.items[index][2]["inner_path"]]
super().__delitem__(index)
# Fast task search by inner_path
def append(self, task):
@ -107,10 +112,11 @@ class WorkerTaskManager(CustomSortedList):
# Create inner path cache for faster lookup by filename
self.inner_paths[task["inner_path"]] = task
def __delitem__(self, index):
# Remove from inner path cache
del self.inner_paths[self.items[index][2]["inner_path"]]
super().__delitem__(index)
def remove(self, task):
if task not in self:
raise ValueError("%r not in list" % task)
else:
super().remove(task)
def findTask(self, inner_path):
return self.inner_paths.get(inner_path, None)