From ba00bcbf7b4f96625e408319b386d0a179240760 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Mon, 18 Apr 2016 15:46:33 +0100 Subject: [PATCH] findClips: select_related('item') / ('item__sort') Clip.public_id uses self.item.public_id. Clip.json() uses self.item.sort, so we should select_related on that rather than the clip's own sort field. (They are identical objects. Is Clip.sort ever used directly?) With this change, findClips() issues one query to fetch clips plus one query per flavour of annotation; before, it issued two extra queries per clip. --- pandora/clip/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandora/clip/views.py b/pandora/clip/views.py index f613c7ee8..fbad2e42d 100644 --- a/pandora/clip/views.py +++ b/pandora/clip/views.py @@ -95,6 +95,7 @@ def findClips(request, data): if 'keys' in data: qs = order_query(qs, query['sort']) qs = qs[query['range'][0]:query['range'][1]] + qs = qs.select_related('item') ids = [] layers = settings.CONFIG['layers'] @@ -102,7 +103,7 @@ def findClips(request, data): layer_ids = [k['id'] for k in layers] keys = filter(lambda k: k not in layer_ids + ['annotations'], data['keys']) if filter(lambda k: k not in models.Clip.clip_keys, keys): - qs = qs.select_related('sort') + qs = qs.select_related('item__sort') def add(p): ids.append(p.id)