From 75b93039b1b4105719bc4fcd748bd6d10594af18 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Wed, 2 Sep 2015 13:15:47 +0100 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 824b7e7..5584639 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 456e42d..b0cfd7a 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): -- 2.4.3