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,22 +163,19 @@ 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:
|
||||||
|
|
|
@ -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