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,22 +163,19 @@ class Annotation(models.Model):
|
|||
self.sortvalue = None
|
||||
self.languages = None
|
||||
|
||||
with transaction.atomic():
|
||||
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.atomic():
|
||||
if set_public_id:
|
||||
self.set_public_id()
|
||||
|
||||
super(Annotation, self).save(*args, **kwargs)
|
||||
|
||||
if self.clip:
|
||||
Clip.objects.filter(**{
|
||||
'id': self.clip.id,
|
||||
self.layer: False
|
||||
}).update(**{self.layer: True})
|
||||
# update clip.findvalue
|
||||
self.clip.save()
|
||||
self.clip.update_findvalue()
|
||||
setattr(self.clip, self.layer, True)
|
||||
self.clip.save(update_fields=[self.layer, 'sortvalue', 'findvalue'])
|
||||
|
||||
# update matches in bulk if called from load_subtitles
|
||||
if not delay_matches:
|
||||
|
|
|
@ -60,9 +60,7 @@ class MetaClip(object):
|
|||
self.hue = self.saturation = self.lightness = 0
|
||||
self.volume = 0
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if self.duration != self.end - self.start:
|
||||
self.update_calculated_values()
|
||||
def update_findvalue(self):
|
||||
if not self.aspect_ratio and self.item:
|
||||
streams = self.item.streams()
|
||||
if streams:
|
||||
|
@ -90,6 +88,11 @@ class MetaClip(object):
|
|||
self.findvalue = '\n'.join(list(filter(None, [a.findvalue for a in anns])))
|
||||
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])))
|
||||
|
||||
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)
|
||||
|
||||
clip_keys = ('id', 'in', 'out', 'position', 'created', 'modified',
|
||||
|
|
Loading…
Reference in a new issue