forked from 0x2620/pandora
smaller transaction, use update_fields to update clip values
This commit is contained in:
parent
e3e5e3b9e5
commit
4be61a3982
2 changed files with 18 additions and 18 deletions
|
@ -163,28 +163,25 @@ class Annotation(models.Model):
|
||||||
self.sortvalue = None
|
self.sortvalue = None
|
||||||
self.languages = None
|
self.languages = None
|
||||||
|
|
||||||
with transaction.atomic():
|
if not self.clip or self.start != self.clip.start or self.end != self.clip.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)
|
||||||
self.clip, created = Clip.get_or_create(self.item, self.start, self.end)
|
|
||||||
|
|
||||||
|
with transaction.atomic():
|
||||||
if set_public_id:
|
if set_public_id:
|
||||||
self.set_public_id()
|
self.set_public_id()
|
||||||
|
|
||||||
super(Annotation, self).save(*args, **kwargs)
|
super(Annotation, self).save(*args, **kwargs)
|
||||||
|
|
||||||
if self.clip:
|
if self.clip:
|
||||||
Clip.objects.filter(**{
|
self.clip.update_findvalue()
|
||||||
'id': self.clip.id,
|
setattr(self.clip, self.layer, True)
|
||||||
self.layer: False
|
self.clip.save(update_fields=[self.layer, 'sortvalue', 'findvalue'])
|
||||||
}).update(**{self.layer: True})
|
|
||||||
# update clip.findvalue
|
|
||||||
self.clip.save()
|
|
||||||
|
|
||||||
# update matches in bulk if called from load_subtitles
|
# update matches in bulk if called from load_subtitles
|
||||||
if not delay_matches:
|
if not delay_matches:
|
||||||
self.update_matches()
|
self.update_matches()
|
||||||
self.update_documents()
|
self.update_documents()
|
||||||
self.update_translations()
|
self.update_translations()
|
||||||
|
|
||||||
def update_matches(self):
|
def update_matches(self):
|
||||||
from place.models import Place
|
from place.models import Place
|
||||||
|
|
|
@ -60,9 +60,7 @@ class MetaClip(object):
|
||||||
self.hue = self.saturation = self.lightness = 0
|
self.hue = self.saturation = self.lightness = 0
|
||||||
self.volume = 0
|
self.volume = 0
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def update_findvalue(self):
|
||||||
if self.duration != self.end - self.start:
|
|
||||||
self.update_calculated_values()
|
|
||||||
if not self.aspect_ratio and self.item:
|
if not self.aspect_ratio and self.item:
|
||||||
streams = self.item.streams()
|
streams = self.item.streams()
|
||||||
if streams:
|
if streams:
|
||||||
|
@ -90,6 +88,11 @@ class MetaClip(object):
|
||||||
self.findvalue = '\n'.join(list(filter(None, [a.findvalue for a in anns])))
|
self.findvalue = '\n'.join(list(filter(None, [a.findvalue for a in anns])))
|
||||||
for l in [k['id'] for k in settings.CONFIG['layers']]:
|
for l in [k['id'] for k in settings.CONFIG['layers']]:
|
||||||
setattr(self, l, l in anns_by_layer and bool(len(anns_by_layer[l])))
|
setattr(self, l, l in anns_by_layer and bool(len(anns_by_layer[l])))
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
if self.duration != self.end - self.start:
|
||||||
|
self.update_calculated_values()
|
||||||
|
self.update_findvalue()
|
||||||
models.Model.save(self, *args, **kwargs)
|
models.Model.save(self, *args, **kwargs)
|
||||||
|
|
||||||
clip_keys = ('id', 'in', 'out', 'position', 'created', 'modified',
|
clip_keys = ('id', 'in', 'out', 'position', 'created', 'modified',
|
||||||
|
|
Loading…
Reference in a new issue