From 0d334173d36ef4a9c452a7ad7aa50eaefee547e5 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Thu, 4 Feb 2016 18:35:33 +0000 Subject: [PATCH] Entity: only update annotations when name has changed (fixes #2877) Just like ace0468 this doesn't exactly fix #2827, but it does reduce the unnecessary work. --- pandora/entity/models.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pandora/entity/models.py b/pandora/entity/models.py index b0cfd7a..11455e7 100644 --- a/pandora/entity/models.py +++ b/pandora/entity/models.py @@ -10,7 +10,7 @@ import unicodedata from django.db import models, transaction from django.db.models import Max from django.contrib.auth.models import User -from django.db.models.signals import pre_delete +from django.db.models.signals import pre_delete, post_init from django.conf import settings import ox @@ -232,11 +232,24 @@ class Entity(models.Model): import annotation.models import annotation.tasks + if self.name == self._original_name: + return + entity_layers = [l['id'] for l in settings.CONFIG['layers'] if l['type'] == 'entity'] if entity_layers: annotation.tasks.update_annotations.delay(entity_layers, self.get_id()) +def entity_post_init(sender, instance, **kwargs): + instance._original_name = instance.name + + +post_init.connect( + entity_post_init, + sender=Entity, +) + + class DocumentProperties(models.Model): class Meta: -- 2.5.0