From 4a671506047a6a40084e11f6524a545761780e93 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Thu, 29 Dec 2011 22:34:53 +0530 Subject: [PATCH] faster clip queries if keys include item keys --- pandora/clip/models.py | 8 ++++---- pandora/clip/views.py | 7 +++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pandora/clip/models.py b/pandora/clip/models.py index 0c47cc423..7b07388ef 100644 --- a/pandora/clip/models.py +++ b/pandora/clip/models.py @@ -40,11 +40,11 @@ class MetaClip: setattr(self, l, self.annotations.filter(layer=l).count()>0) models.Model.save(self, *args, **kwargs) + clip_keys = ('id', 'in', 'out', 'position', 'created', 'modified', + 'hue', 'saturation', 'lightness', 'volume', 'videoRatio') def json(self, keys=None): j = {} - clip_keys = ('id', 'in', 'out', 'position', 'created', 'modified', - 'hue', 'saturation', 'lightness', 'volume', 'videoRatio') - for key in clip_keys: + for key in self.clip_keys: j[key] = getattr(self, { 'id': 'public_id', 'in': 'start', @@ -61,7 +61,7 @@ class MetaClip: j['annotations'] = [a.json(keys=['value', 'id', 'layer']) for a in self.annotations.filter(layer__in=self.layers)] for key in keys: - if key not in clip_keys and key not in j: + if key not in self.clip_keys and key not in j: value = self.item.get(key) if not value and hasattr(self.item.sort, key): value = getattr(self.item.sort, key) diff --git a/pandora/clip/views.py b/pandora/clip/views.py index 53e768a5e..4d691d79d 100644 --- a/pandora/clip/views.py +++ b/pandora/clip/views.py @@ -35,7 +35,7 @@ def order_query(qs, sort): if operator != '-': operator = '' clip_keys = ('public_id', 'start', 'end', 'hue', 'saturation', 'lightness', 'volume', - 'annotations__sortvalue', 'videoRatio', + 'duration', 'annotations__sortvalue', 'videoRatio', 'director', 'title') key = { 'id': 'public_id', @@ -82,9 +82,12 @@ def findClips(request): if 'keys' in data: qs = order_query(qs, query['sort']) qs = qs[query['range'][0]:query['range'][1]] - #qs = qs.select_related('item__sort') + ids = [] keys = filter(lambda k: k not in models.Clip.layers, data['keys']) + if filter(lambda k: k not in models.Clip.clip_keys, keys): + qs = qs.select_related('item__sort') + def add(p): ids.append(p.id) return p.json(keys=keys)