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 re
|
||||||
import unicodedata
|
import unicodedata
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models, transaction
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
@ -162,34 +162,36 @@ class Annotation(models.Model):
|
||||||
self.sortvalue = None
|
self.sortvalue = None
|
||||||
self.languages = None
|
self.languages = None
|
||||||
|
|
||||||
if not self.clip or self.start != self.clip.start or self.end != self.clip.end:
|
with transaction.commit_on_success():
|
||||||
self.clip, created = Clip.get_or_create(self.item, self.start, self.end)
|
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)
|
||||||
|
|
||||||
super(Annotation, self).save(*args, **kwargs)
|
super(Annotation, self).save(*args, **kwargs)
|
||||||
if set_public_id:
|
if set_public_id:
|
||||||
self.set_public_id()
|
self.set_public_id()
|
||||||
|
|
||||||
if self.clip:
|
if self.clip:
|
||||||
Clip.objects.filter(**{
|
Clip.objects.filter(**{
|
||||||
'id': self.clip.id,
|
'id': self.clip.id,
|
||||||
self.layer: False
|
self.layer: False
|
||||||
}).update(**{self.layer: True})
|
}).update(**{self.layer: True})
|
||||||
#update clip.findvalue
|
#update clip.findvalue
|
||||||
self.clip.save()
|
self.clip.save()
|
||||||
|
|
||||||
#editAnnotations needs to be in snyc
|
#editAnnotations needs to be in snyc
|
||||||
if layer.get('type') == 'place' or layer.get('hasPlaces'):
|
if layer.get('type') == 'place' or layer.get('hasPlaces'):
|
||||||
update_matches(self.id, 'place')
|
update_matches(self.id, 'place')
|
||||||
if layer.get('type') == 'event' or layer.get('hasEvents'):
|
if layer.get('type') == 'event' or layer.get('hasEvents'):
|
||||||
update_matches(self.id, 'event')
|
update_matches(self.id, 'event')
|
||||||
|
|
||||||
def delete(self, *args, **kwargs):
|
def delete(self, *args, **kwargs):
|
||||||
super(Annotation, self).delete(*args, **kwargs)
|
with transaction.commit_on_success():
|
||||||
if self.clip and self.clip.annotations.count() == 0:
|
super(Annotation, self).delete(*args, **kwargs)
|
||||||
self.clip.delete()
|
if self.clip and self.clip.annotations.count() == 0:
|
||||||
self.item.update_find()
|
self.clip.delete()
|
||||||
self.item.update_sort()
|
self.item.update_find()
|
||||||
self.item.update_facets()
|
self.item.update_sort()
|
||||||
|
self.item.update_facets()
|
||||||
|
|
||||||
def cleanup_undefined_relations(self):
|
def cleanup_undefined_relations(self):
|
||||||
layer = self.get_layer()
|
layer = self.get_layer()
|
||||||
|
|
|
@ -100,12 +100,13 @@ def update_item(id):
|
||||||
#cleanup orphaned clips
|
#cleanup orphaned clips
|
||||||
Clip.objects.filter(item__id=a.item.id, annotations__id=None).delete()
|
Clip.objects.filter(item__id=a.item.id, annotations__id=None).delete()
|
||||||
#update facets if needed
|
#update facets if needed
|
||||||
if filter(lambda f: f['id'] == a.layer and f.get('filter'), settings.CONFIG['itemKeys']):
|
with transaction.commit_on_sucess():
|
||||||
a.item.update_layer_facet(a.layer)
|
if filter(lambda f: f['id'] == a.layer and f.get('filter'), settings.CONFIG['itemKeys']):
|
||||||
Item.objects.filter(id=a.item.id).update(modified=a.modified)
|
a.item.update_layer_facet(a.layer)
|
||||||
a.item.modified = a.modified
|
Item.objects.filter(id=a.item.id).update(modified=a.modified)
|
||||||
a.item.update_find()
|
a.item.modified = a.modified
|
||||||
a.item.update_sort()
|
a.item.update_find()
|
||||||
a.item.update_facets()
|
a.item.update_sort()
|
||||||
if a.item.update_languages():
|
a.item.update_facets()
|
||||||
a.item.save()
|
if a.item.update_languages():
|
||||||
|
a.item.save()
|
||||||
|
|
Loading…
Reference in a new issue