From 8bb18af181312d246bb6369c5d2ab8b655a5f1b4 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sat, 29 Oct 2011 12:39:33 +0200 Subject: [PATCH] more clip query speedups --- pandora/annotation/models.py | 4 ++-- pandora/clip/models.py | 1 - pandora/clip/views.py | 8 ++++++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pandora/annotation/models.py b/pandora/annotation/models.py index 4eba78f57..74e76eff2 100644 --- a/pandora/annotation/models.py +++ b/pandora/annotation/models.py @@ -32,8 +32,8 @@ def create_or_update_layer(data): class Layer(models.Model): - class Meta: - ordering = ('position', ) + #class Meta: + # ordering = ('position', ) enabled = models.BooleanField(default=True) diff --git a/pandora/clip/models.py b/pandora/clip/models.py index 5b9eda3d3..920f67040 100644 --- a/pandora/clip/models.py +++ b/pandora/clip/models.py @@ -89,7 +89,6 @@ class Clip(models.Model): for layer in filter(lambda l: l in keys, public_layers): j[layer] = [a.json(keys=['id', 'value']) for a in self.annotations.filter(layer__name=layer)] - for key in keys: if key not in clip_keys and key not in j: value = self.item.get(key) diff --git a/pandora/clip/views.py b/pandora/clip/views.py index d53ed253e..5bfbae967 100644 --- a/pandora/clip/views.py +++ b/pandora/clip/views.py @@ -75,12 +75,15 @@ def findClips(request): response = json_response() query = parse_query(data, request.user) - qs = order_query(query['qs'], query['sort']) + qs = query['qs'] if 'keys' in data: + qs = order_query(qs, query['sort']) qs = qs[query['range'][0]:query['range'][1]] - qs = qs.select_related() + qs = qs.select_related('item__sort') + #qs = qs.prefetch_related('annotations') response['data']['items'] = [p.json(keys=data['keys']) for p in qs] elif 'position' in query: + qs = order_query(qs, query['sort']) ids = [i.public_id for i in qs] data['conditions'] = data['conditions'] + { 'value': data['position'], @@ -92,6 +95,7 @@ def findClips(request): if qs.count() > 0: response['data']['position'] = utils.get_positions(ids, [qs[0].itemId])[0] elif 'positions' in data: + qs = order_query(qs, query['sort']) ids = [i.public_id for i in qs] response['data']['positions'] = utils.get_positions(ids, data['positions']) else: