forked from 0x2620/pandora
wrap annotation updates into transactions
This commit is contained in:
parent
86ab36c6a6
commit
928cc11663
2 changed files with 36 additions and 33 deletions
|
@ -4,7 +4,7 @@ from __future__ import division, with_statement
|
|||
import re
|
||||
import unicodedata
|
||||
|
||||
from django.db import models
|
||||
from django.db import models, transaction
|
||||
from django.db.models import Q
|
||||
from django.contrib.auth.models import User
|
||||
from django.conf import settings
|
||||
|
@ -162,6 +162,7 @@ class Annotation(models.Model):
|
|||
self.sortvalue = None
|
||||
self.languages = None
|
||||
|
||||
with transaction.commit_on_success():
|
||||
if not self.clip or self.start != self.clip.start or self.end != self.clip.end:
|
||||
self.clip, created = Clip.get_or_create(self.item, self.start, self.end)
|
||||
|
||||
|
@ -184,6 +185,7 @@ class Annotation(models.Model):
|
|||
update_matches(self.id, 'event')
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
with transaction.commit_on_success():
|
||||
super(Annotation, self).delete(*args, **kwargs)
|
||||
if self.clip and self.clip.annotations.count() == 0:
|
||||
self.clip.delete()
|
||||
|
|
|
@ -100,6 +100,7 @@ def update_item(id):
|
|||
#cleanup orphaned clips
|
||||
Clip.objects.filter(item__id=a.item.id, annotations__id=None).delete()
|
||||
#update facets if needed
|
||||
with transaction.commit_on_sucess():
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue