cache stream aspect ratio in clips table. speedup clips view
This commit is contained in:
parent
50e15ad3b0
commit
d3fdb4f578
2 changed files with 15 additions and 10 deletions
|
@ -22,6 +22,7 @@ class Clip(models.Model):
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
modified = models.DateTimeField(auto_now=True)
|
modified = models.DateTimeField(auto_now=True)
|
||||||
public_id = models.CharField(max_length=128, unique=True)
|
public_id = models.CharField(max_length=128, unique=True)
|
||||||
|
aspect_ratio = models.FloatField(default=0)
|
||||||
|
|
||||||
item = models.ForeignKey('item.Item', related_name='clips')
|
item = models.ForeignKey('item.Item', related_name='clips')
|
||||||
|
|
||||||
|
@ -37,8 +38,8 @@ class Clip(models.Model):
|
||||||
lightness = models.FloatField(default=0, db_index=True)
|
lightness = models.FloatField(default=0, db_index=True)
|
||||||
volume = models.FloatField(default=0, null=True, db_index=True)
|
volume = models.FloatField(default=0, null=True, db_index=True)
|
||||||
|
|
||||||
director = models.CharField(max_length=1000)
|
director = models.CharField(max_length=1000, db_index=True)
|
||||||
title = models.CharField(max_length=1000)
|
title = models.CharField(max_length=1000, db_index=True)
|
||||||
|
|
||||||
def update_calculated_values(self):
|
def update_calculated_values(self):
|
||||||
self.duration = self.end - self.start
|
self.duration = self.end - self.start
|
||||||
|
@ -56,36 +57,39 @@ class Clip(models.Model):
|
||||||
self.public_id = u"%s/%s-%s" %(self.item.itemId, float(self.start), float(self.end))
|
self.public_id = u"%s/%s-%s" %(self.item.itemId, float(self.start), float(self.end))
|
||||||
if self.duration != self.end - self.start:
|
if self.duration != self.end - self.start:
|
||||||
self.update_calculated_values()
|
self.update_calculated_values()
|
||||||
|
if not self.aspect_ratio and self.item:
|
||||||
|
streams = self.item.streams()
|
||||||
|
if streams:
|
||||||
|
self.aspect_ratio = streams[0].aspect_ratio
|
||||||
super(Clip, self).save(*args, **kwargs)
|
super(Clip, self).save(*args, **kwargs)
|
||||||
|
|
||||||
def json(self, keys=None):
|
def json(self, keys=None):
|
||||||
j = {}
|
j = {}
|
||||||
clip_keys = ('id', 'in', 'out', 'position', 'created', 'modified',
|
clip_keys = ('id', 'in', 'out', 'position', 'created', 'modified',
|
||||||
'hue', 'saturation', 'lightness', 'volume')
|
'hue', 'saturation', 'lightness', 'volume', 'videoRatio')
|
||||||
for key in clip_keys:
|
for key in clip_keys:
|
||||||
j[key] = getattr(self, {
|
j[key] = getattr(self, {
|
||||||
'id': 'public_id',
|
'id': 'public_id',
|
||||||
'in': 'start',
|
'in': 'start',
|
||||||
'out': 'end',
|
'out': 'end',
|
||||||
'position': 'start',
|
'position': 'start',
|
||||||
|
'videoRatio': 'aspect_ratio',
|
||||||
}.get(key, key))
|
}.get(key, key))
|
||||||
if keys:
|
if keys:
|
||||||
for key in j.keys():
|
for key in j.keys():
|
||||||
if key not in keys:
|
if key not in keys:
|
||||||
del j[key]
|
del j[key]
|
||||||
if 'videoRatio' in keys:
|
|
||||||
streams = self.item.streams()
|
|
||||||
if streams:
|
|
||||||
j['videoRatio'] = streams[0].aspect_ratio
|
|
||||||
public_layers = [l['id']
|
public_layers = [l['id']
|
||||||
for l in filter(lambda l: not l.get('private', False),
|
for l in filter(lambda l: not l.get('private', False),
|
||||||
settings.CONFIG['layers'])]
|
settings.CONFIG['layers'])]
|
||||||
if 'annotations' in keys:
|
if 'annotations' in keys:
|
||||||
j['annotations'] = [a.json(keys=['value', 'id', 'layer'])
|
j['annotations'] = [a.json(keys=['value', 'id', 'layer'])
|
||||||
for a in self.annotations.filter(layer__name__in=public_layers).select_related()]
|
for a in self.annotations.filter(layer__name__in=public_layers).select_related()]
|
||||||
|
|
||||||
for layer in filter(lambda l: l in keys, public_layers):
|
for layer in filter(lambda l: l in keys, public_layers):
|
||||||
j[layer] = [a.json(keys=['id', 'value'])
|
j[layer] = [a.json(keys=['id', 'value'])
|
||||||
for a in self.annotations.filter(layer__name=layer)]
|
for a in self.annotations.filter(layer__name=layer)]
|
||||||
|
|
||||||
for key in keys:
|
for key in keys:
|
||||||
if key not in clip_keys and key not in j:
|
if key not in clip_keys and key not in j:
|
||||||
value = self.item.get(key)
|
value = self.item.get(key)
|
||||||
|
|
|
@ -32,7 +32,7 @@ def order_query(qs, sort):
|
||||||
if operator != '-':
|
if operator != '-':
|
||||||
operator = ''
|
operator = ''
|
||||||
clip_keys = ('public_id', 'start', 'end', 'hue', 'saturation', 'lightness', 'volume',
|
clip_keys = ('public_id', 'start', 'end', 'hue', 'saturation', 'lightness', 'volume',
|
||||||
'annotations__value',
|
'annotations__value', 'videoRatio',
|
||||||
'director', 'title')
|
'director', 'title')
|
||||||
key = {
|
key = {
|
||||||
'id': 'public_id',
|
'id': 'public_id',
|
||||||
|
@ -40,6 +40,7 @@ def order_query(qs, sort):
|
||||||
'out': 'end',
|
'out': 'end',
|
||||||
'position': 'start',
|
'position': 'start',
|
||||||
'text': 'annotations__value',
|
'text': 'annotations__value',
|
||||||
|
'videoRatio': 'aspect_ratio',
|
||||||
}.get(e['key'], e['key'])
|
}.get(e['key'], e['key'])
|
||||||
if key.startswith('clip:'):
|
if key.startswith('clip:'):
|
||||||
key = e['key'][len('clip:'):]
|
key = e['key'][len('clip:'):]
|
||||||
|
@ -76,8 +77,8 @@ def findClips(request):
|
||||||
query = parse_query(data, request.user)
|
query = parse_query(data, request.user)
|
||||||
qs = order_query(query['qs'], query['sort'])
|
qs = order_query(query['qs'], query['sort'])
|
||||||
if 'keys' in data:
|
if 'keys' in data:
|
||||||
qs = qs.select_related()
|
|
||||||
qs = qs[query['range'][0]:query['range'][1]]
|
qs = qs[query['range'][0]:query['range'][1]]
|
||||||
|
qs = qs.select_related()
|
||||||
response['data']['items'] = [p.json(keys=data['keys']) for p in qs]
|
response['data']['items'] = [p.json(keys=data['keys']) for p in qs]
|
||||||
elif 'position' in query:
|
elif 'position' in query:
|
||||||
ids = [i.public_id for i in qs]
|
ids = [i.public_id for i in qs]
|
||||||
|
|
Loading…
Reference in a new issue