From 5b933c22d806e9ad12242fa2970d07366c65a36f Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sun, 9 Oct 2011 15:39:45 +0200 Subject: [PATCH] select related for some queries --- pandora/annotation/views.py | 2 +- pandora/api/views.py | 5 +++-- pandora/event/views.py | 1 + pandora/item/views.py | 1 + pandora/place/views.py | 1 + 5 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pandora/annotation/views.py b/pandora/annotation/views.py index e91cf3d5..df14e581 100644 --- a/pandora/annotation/views.py +++ b/pandora/annotation/views.py @@ -84,7 +84,7 @@ def findAnnotations(request): query = parse_query(data, request.user) qs = order_query(query['qs'], query['sort']) if 'keys' in data: - qs = qs[query['range'][0]:query['range'][1]] + qs = qs.select_related()[query['range'][0]:query['range'][1]] response['data']['items'] = [p.json(keys=data['keys']) for p in qs] elif 'position' in query: ids = [i.public_id for i in qs] diff --git a/pandora/api/views.py b/pandora/api/views.py index 9622cdac..aac4b3a8 100644 --- a/pandora/api/views.py +++ b/pandora/api/views.py @@ -13,7 +13,7 @@ from django.db.models import Max, Sum from ox.django.shortcuts import render_to_json_response, json_response from ox.utils import json -from user.models import init_user +from user.models import init_user, get_ui from item.models import ItemSort from actions import actions @@ -73,7 +73,8 @@ def init(request): response['data']['user'] = init_user(request.user, request) else: response['data']['user'] = response['data']['site']['user'] - + response['data']['user']['ui'] = get_ui(json.loads(request.session.get('ui', '{}'))) + print request.session, request.session.keys() return render_to_json_response(response) actions.register(init) diff --git a/pandora/event/views.py b/pandora/event/views.py index c651ff08..d3de22de 100644 --- a/pandora/event/views.py +++ b/pandora/event/views.py @@ -171,6 +171,7 @@ Positions qs = query['qs'].distinct() if 'keys' in data: qs = qs[query['range'][0]:query['range'][1]] + qs = qs.select_realed() response['data']['items'] = [p.json(request.user) for p in qs] elif 'position' in query: ids = [i.get_id() for i in qs] diff --git a/pandora/item/views.py b/pandora/item/views.py index 81adf6dd..69795ec6 100644 --- a/pandora/item/views.py +++ b/pandora/item/views.py @@ -249,6 +249,7 @@ Positions if 'accessed' in _p: qs = qs.annotate(a=Max('accessed__access')) if 'viewed' in _p or 'popularity' in _p or 'accessed' in _p: + qs = qs.select_realed() response['data']['items'] = [only_p_sums(m) for m in qs] else: response['data']['items'] = [only_p(m['json']) for m in qs.values('json')] diff --git a/pandora/place/views.py b/pandora/place/views.py index bd9268f5..aeb57c0e 100644 --- a/pandora/place/views.py +++ b/pandora/place/views.py @@ -246,6 +246,7 @@ Positions qs = order_query(query['qs'], query['sort']) qs = qs.distinct() if 'keys' in data: + qs = qs.select_realed() qs = qs[query['range'][0]:query['range'][1]] response['data']['items'] = [p.json(data['keys'], request.user) for p in qs] elif 'position' in query: