From 34f2cfe29034e2e4d0d6cb7b2eb765e02c989791 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Wed, 20 May 2015 00:20:50 +0530 Subject: [PATCH] avoid updating item if another annotation was added or edited since dispatching the update_item event --- pandora/annotation/tasks.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/pandora/annotation/tasks.py b/pandora/annotation/tasks.py index b56a4ae2c..1d7495c8b 100644 --- a/pandora/annotation/tasks.py +++ b/pandora/annotation/tasks.py @@ -109,16 +109,17 @@ def update_item(id): from item.models import Item from clip.models import Clip a = models.Annotation.objects.get(pk=id) - #cleanup orphaned clips - Clip.objects.filter(item__id=a.item.id, annotations__id=None).delete() - #update facets if needed - with transaction.commit_on_success(): - if filter(lambda f: f['id'] == a.layer and f.get('filter'), settings.CONFIG['itemKeys']): - a.item.update_layer_facet(a.layer) - Item.objects.filter(id=a.item.id).update(modified=a.modified) - a.item.modified = a.modified - a.item.update_find() - a.item.update_sort() - a.item.update_facets() - if a.item.update_languages(): - a.item.save() + if a.modified >= a.item.annotations.order_by('-modified')[0].modified: + #cleanup orphaned clips + Clip.objects.filter(item__id=a.item.id, annotations__id=None).delete() + #update facets if needed + with transaction.commit_on_success(): + if filter(lambda f: f['id'] == a.layer and f.get('filter'), settings.CONFIG['itemKeys']): + a.item.update_layer_facet(a.layer) + Item.objects.filter(id=a.item.id).update(modified=a.modified) + a.item.modified = a.modified + a.item.update_find() + a.item.update_sort() + a.item.update_facets() + if a.item.update_languages(): + a.item.save()