Entity.save(): update annotations async (fixes #2827, kinda)

This commit is contained in:
Will Thompson 2015-09-02 14:32:16 +02:00 committed by j
parent 41b50ccdb8
commit ace04688f2
2 changed files with 18 additions and 10 deletions

View file

@ -123,3 +123,19 @@ def update_item(id, force=False):
a.item.update_facets()
if a.item.update_languages():
a.item.save()
@task(ignore_results=True, queue='default')
def update_annotations(layers, value):
items = {}
with transaction.commit_on_success():
for a in models.Annotation.objects.filter(
layer__in=layers,
value=value
):
a.save()
items[a.item.id] = a.id
for id in items.values():
update_item.delay(id, True)

View file

@ -234,16 +234,8 @@ class Entity(models.Model):
entity_layers = [l['id'] for l in settings.CONFIG['layers'] if l['type'] == 'entity']
if entity_layers:
with transaction.commit_on_success():
items = {}
for a in annotation.models.Annotation.objects.filter(
layer__in=entity_layers,
value=self.get_id()
):
a.save()
items[a.item.id] = a.id
for id in items.values():
annotation.tasks.update_item.delay(id, True)
annotation.tasks.update_annotations.delay(entity_layers, self.get_id())
class DocumentProperties(models.Model):