select related for some queries

This commit is contained in:
j 2011-10-09 15:39:45 +02:00
parent 9f63a45c2e
commit 5b933c22d8
5 changed files with 7 additions and 3 deletions

View file

@ -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]

View file

@ -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)

View file

@ -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]

View file

@ -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')]

View file

@ -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: