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,34 +162,36 @@ class Annotation(models.Model):
|
|||
self.sortvalue = None
|
||||
self.languages = None
|
||||
|
||||
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)
|
||||
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)
|
||||
|
||||
super(Annotation, self).save(*args, **kwargs)
|
||||
if set_public_id:
|
||||
self.set_public_id()
|
||||
super(Annotation, self).save(*args, **kwargs)
|
||||
if set_public_id:
|
||||
self.set_public_id()
|
||||
|
||||
if self.clip:
|
||||
Clip.objects.filter(**{
|
||||
'id': self.clip.id,
|
||||
self.layer: False
|
||||
}).update(**{self.layer: True})
|
||||
#update clip.findvalue
|
||||
self.clip.save()
|
||||
if self.clip:
|
||||
Clip.objects.filter(**{
|
||||
'id': self.clip.id,
|
||||
self.layer: False
|
||||
}).update(**{self.layer: True})
|
||||
#update clip.findvalue
|
||||
self.clip.save()
|
||||
|
||||
#editAnnotations needs to be in snyc
|
||||
if layer.get('type') == 'place' or layer.get('hasPlaces'):
|
||||
update_matches(self.id, 'place')
|
||||
if layer.get('type') == 'event' or layer.get('hasEvents'):
|
||||
update_matches(self.id, 'event')
|
||||
#editAnnotations needs to be in snyc
|
||||
if layer.get('type') == 'place' or layer.get('hasPlaces'):
|
||||
update_matches(self.id, 'place')
|
||||
if layer.get('type') == 'event' or layer.get('hasEvents'):
|
||||
update_matches(self.id, 'event')
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
super(Annotation, self).delete(*args, **kwargs)
|
||||
if self.clip and self.clip.annotations.count() == 0:
|
||||
self.clip.delete()
|
||||
self.item.update_find()
|
||||
self.item.update_sort()
|
||||
self.item.update_facets()
|
||||
with transaction.commit_on_success():
|
||||
super(Annotation, self).delete(*args, **kwargs)
|
||||
if self.clip and self.clip.annotations.count() == 0:
|
||||
self.clip.delete()
|
||||
self.item.update_find()
|
||||
self.item.update_sort()
|
||||
self.item.update_facets()
|
||||
|
||||
def cleanup_undefined_relations(self):
|
||||
layer = self.get_layer()
|
||||
|
|
|
@ -100,12 +100,13 @@ def update_item(id):
|
|||
#cleanup orphaned clips
|
||||
Clip.objects.filter(item__id=a.item.id, annotations__id=None).delete()
|
||||
#update facets if needed
|
||||
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()
|
||||
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)
|
||||
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()
|
||||
|
|
Loading…
Reference in a new issue