From abf445b7f1231d6593d0c38b4fb044f6cd103dbc Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sat, 25 Apr 2015 19:02:34 +0200 Subject: [PATCH] faster edits --- pandora/clip/models.py | 23 ++++++++++++----------- pandora/edit/models.py | 8 +++++--- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/pandora/clip/models.py b/pandora/clip/models.py index d49f16396..0045c16c4 100644 --- a/pandora/clip/models.py +++ b/pandora/clip/models.py @@ -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) - for a in qs.order_by('start'): - ll.append(a.json(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'): + 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 diff --git a/pandora/edit/models.py b/pandora/edit/models.py index 96e52445f..2991e0a3e 100644 --- a/pandora/edit/models.py +++ b/pandora/edit/models.py @@ -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