This commit is contained in:
j 2018-11-15 11:17:48 +00:00
parent 72bb3ba6c1
commit c039279984
3 changed files with 30 additions and 41 deletions

View file

@ -145,11 +145,7 @@ class ClipManager(Manager):
keys = layer_ids + ['annotations', 'text', '*'] keys = layer_ids + ['annotations', 'text', '*']
conditions = data.get('query', {}).get('conditions', []) conditions = data.get('query', {}).get('conditions', [])
conditions = flatten_conditions(conditions) conditions = flatten_conditions(conditions)
conditions_ = [] conditions = list(filter(lambda c: c.get('key') in keys, conditions))
for c in conditions:
if c.get('key') in keys and c not in conditions_:
conditions_.append(c)
conditions = conditions_
operator = data.get('query', {}).get('operator', '&') operator = data.get('query', {}).get('operator', '&')
def parse(condition): def parse(condition):

View file

@ -95,7 +95,7 @@ def findClips(request, data):
if 'keys' in data: if 'keys' in data:
qs = order_query(qs, query['sort']) qs = order_query(qs, query['sort'])
qs = qs[query['range'][0]:query['range'][1]] qs = qs[query['range'][0]:query['range'][1]]
#qs = qs.select_related('item') qs = qs.select_related('item')
layers = settings.CONFIG['layers'] layers = settings.CONFIG['layers']
entity_layer_ids = [k['id'] for k in layers if k['type'] == 'entity'] entity_layer_ids = [k['id'] for k in layers if k['type'] == 'entity']

View file

@ -11,10 +11,9 @@ import tempfile
from six.moves.urllib.parse import quote from six.moves.urllib.parse import quote
import ox import ox
from django.conf import settings from django.conf import settings
from django.contrib.auth import get_user_model
from django.core.cache import cache
from django.db import models, transaction from django.db import models, transaction
from django.db.models import Max from django.db.models import Max
from django.contrib.auth import get_user_model
from django.utils.encoding import python_2_unicode_compatible from django.utils.encoding import python_2_unicode_compatible
from oxdjango.fields import JSONField from oxdjango.fields import JSONField
@ -119,7 +118,7 @@ class Edit(models.Model):
c = self.add_clip(data) c = self.add_clip(data)
if c: if c:
ids.insert(index, c.id) ids.insert(index, c.id)
added.append(c.json(user=user)) added.append(c.json(user))
added[-1]['index'] = index added[-1]['index'] = index
index += 1 index += 1
else: else:
@ -489,38 +488,32 @@ class Clip(models.Model):
self.sortvolume = 0 self.sortvolume = 0
def json(self, user=None): def json(self, user=None):
cache_key = 'edit:clip:' + str(self.get_id()) data = {
if user: 'id': self.get_id(),
cache_key += ':' + user.username 'index': self.index,
data = cache.get(cache_key) 'volume': self.volume,
if not data: }
data = { if self.annotation:
'id': self.get_id(), data['annotation'] = self.annotation.public_id
'index': self.index, data['item'] = self.item.public_id
'volume': self.volume, data['in'] = self.annotation.start
} data['out'] = self.annotation.end
if self.annotation: data['parts'] = self.annotation.item.cache['parts']
data['annotation'] = self.annotation.public_id data['durations'] = self.annotation.item.cache['durations']
data['item'] = self.item.public_id else:
data['in'] = self.annotation.start data['item'] = self.item.public_id
data['out'] = self.annotation.end data['in'] = self.start
data['parts'] = self.annotation.item.cache['parts'] data['out'] = self.end
data['durations'] = self.annotation.item.cache['durations'] data['parts'] = self.item.cache['parts']
else: data['durations'] = self.item.cache['durations']
data['item'] = self.item.public_id for key in ('title', 'director', 'year', 'videoRatio'):
data['in'] = self.start value = self.item.cache.get(key)
data['out'] = self.end if value:
data['parts'] = self.item.cache['parts'] data[key] = value
data['durations'] = self.item.cache['durations'] data['duration'] = data['out'] - data['in']
for key in ('title', 'director', 'year', 'videoRatio'): data['cuts'] = tuple([c for c in self.item.get('cuts', []) if c > self.start and c < self.end])
value = self.item.cache.get(key) data['layers'] = self.get_layers(user)
if value: data['streams'] = [s.file.oshash for s in self.item.streams()]
data[key] = value
data['duration'] = data['out'] - data['in']
data['cuts'] = tuple([c for c in self.item.get('cuts', []) if c > self.start and c < self.end])
data['layers'] = self.get_layers(user)
data['streams'] = [s.file.oshash for s in self.item.streams()]
cache.set(cache_key, data, 180)
return data return data
def get_annotations(self): def get_annotations(self):