From ace04688f22a142212e101dddf286470a500d834 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Wed, 2 Sep 2015 14:32:16 +0200 Subject: [PATCH] Entity.save(): update annotations async (fixes #2827, kinda) --- pandora/annotation/tasks.py | 16 ++++++++++++++++ pandora/entity/models.py | 12 ++---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/pandora/annotation/tasks.py b/pandora/annotation/tasks.py index 824b7e797..5584639e3 100644 --- a/pandora/annotation/tasks.py +++ b/pandora/annotation/tasks.py @@ -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) diff --git a/pandora/entity/models.py b/pandora/entity/models.py index 456e42d21..b0cfd7a16 100644 --- a/pandora/entity/models.py +++ b/pandora/entity/models.py @@ -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):