faster edits

This commit is contained in:
j 2015-04-25 19:02:34 +02:00
parent e666159811
commit abf445b7f1
2 changed files with 17 additions and 14 deletions

View file

@ -118,20 +118,21 @@ class MetaClip:
end = self.end
item = self.item
layers = {}
private = []
for l in settings.CONFIG['layers']:
name = l['id']
ll = layers.setdefault(name, [])
qs = Annotation.objects.filter(layer=name, item=item).order_by(
'start', 'end', 'sortvalue')
if name == 'subtitles':
qs = qs.exclude(value='')
qs = qs.filter(start__lt=end, end__gt=start)
layers[name] = []
if l.get('private'):
if user and user.is_anonymous():
user = None
qs = qs.filter(user=user)
private.append(name)
qs = Annotation.objects.filter(item=item).exclude(value='')
qs = qs.order_by('start', 'end', 'sortvalue')
qs = qs.filter(start__lt=end, end__gt=start)
for a in qs.order_by('start'):
ll.append(a.json(user=user))
if a.layer in private:
if a.user == user:
layers[a.layer].append(a.json(user=user))
else:
layers[a.layer].append(a.json(user=user))
return layers
@classmethod

View file

@ -229,7 +229,8 @@ class Edit(models.Model):
clips_query = self.clip_query()
if clips_query['conditions']:
clips = clip.models.Clip.objects.find({'query': clips_query}, user)
clips = clips.filter(item__in=self.get_items(user))
items = [i['id'] for i in self.get_items(user).values('id')]
clips = clips.filter(item__in=items)
else:
clips = None
return clips
@ -272,9 +273,10 @@ class Edit(models.Model):
frames = []
if not self.poster_frames:
items = self.get_items(self.user).filter(rendered=True)
if 0 < items.count() <= 1000:
items_count = items.count()
if 0 < items_count <= 1000:
poster_frames = []
for i in range(0, items.count(), max(1, int(items.count()/4))):
for i in range(0, items_count, max(1, int(items_count/4))):
poster_frames.append({
'item': items[int(i)].public_id,
'position': items[int(i)].poster_frame