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 end = self.end
item = self.item item = self.item
layers = {} layers = {}
private = []
for l in settings.CONFIG['layers']: for l in settings.CONFIG['layers']:
name = l['id'] name = l['id']
ll = layers.setdefault(name, []) layers[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)
if l.get('private'): if l.get('private'):
if user and user.is_anonymous(): private.append(name)
user = None qs = Annotation.objects.filter(item=item).exclude(value='')
qs = qs.filter(user=user) qs = qs.order_by('start', 'end', 'sortvalue')
qs = qs.filter(start__lt=end, end__gt=start)
for a in qs.order_by('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 return layers
@classmethod @classmethod

View file

@ -229,7 +229,8 @@ class Edit(models.Model):
clips_query = self.clip_query() clips_query = self.clip_query()
if clips_query['conditions']: if clips_query['conditions']:
clips = clip.models.Clip.objects.find({'query': clips_query}, user) 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: else:
clips = None clips = None
return clips return clips
@ -272,9 +273,10 @@ class Edit(models.Model):
frames = [] frames = []
if not self.poster_frames: if not self.poster_frames:
items = self.get_items(self.user).filter(rendered=True) 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 = [] 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({ poster_frames.append({
'item': items[int(i)].public_id, 'item': items[int(i)].public_id,
'position': items[int(i)].poster_frame 'position': items[int(i)].poster_frame