select related for some queries
This commit is contained in:
parent
9f63a45c2e
commit
5b933c22d8
5 changed files with 7 additions and 3 deletions
|
@ -84,7 +84,7 @@ def findAnnotations(request):
|
||||||
query = parse_query(data, request.user)
|
query = parse_query(data, request.user)
|
||||||
qs = order_query(query['qs'], query['sort'])
|
qs = order_query(query['qs'], query['sort'])
|
||||||
if 'keys' in data:
|
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]
|
response['data']['items'] = [p.json(keys=data['keys']) for p in qs]
|
||||||
elif 'position' in query:
|
elif 'position' in query:
|
||||||
ids = [i.public_id for i in qs]
|
ids = [i.public_id for i in qs]
|
||||||
|
|
|
@ -13,7 +13,7 @@ from django.db.models import Max, Sum
|
||||||
from ox.django.shortcuts import render_to_json_response, json_response
|
from ox.django.shortcuts import render_to_json_response, json_response
|
||||||
from ox.utils import json
|
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 item.models import ItemSort
|
||||||
|
|
||||||
from actions import actions
|
from actions import actions
|
||||||
|
@ -73,7 +73,8 @@ def init(request):
|
||||||
response['data']['user'] = init_user(request.user, request)
|
response['data']['user'] = init_user(request.user, request)
|
||||||
else:
|
else:
|
||||||
response['data']['user'] = response['data']['site']['user']
|
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)
|
return render_to_json_response(response)
|
||||||
actions.register(init)
|
actions.register(init)
|
||||||
|
|
||||||
|
|
|
@ -171,6 +171,7 @@ Positions
|
||||||
qs = query['qs'].distinct()
|
qs = query['qs'].distinct()
|
||||||
if 'keys' in data:
|
if 'keys' in data:
|
||||||
qs = qs[query['range'][0]:query['range'][1]]
|
qs = qs[query['range'][0]:query['range'][1]]
|
||||||
|
qs = qs.select_realed()
|
||||||
response['data']['items'] = [p.json(request.user) for p in qs]
|
response['data']['items'] = [p.json(request.user) for p in qs]
|
||||||
elif 'position' in query:
|
elif 'position' in query:
|
||||||
ids = [i.get_id() for i in qs]
|
ids = [i.get_id() for i in qs]
|
||||||
|
|
|
@ -249,6 +249,7 @@ Positions
|
||||||
if 'accessed' in _p:
|
if 'accessed' in _p:
|
||||||
qs = qs.annotate(a=Max('accessed__access'))
|
qs = qs.annotate(a=Max('accessed__access'))
|
||||||
if 'viewed' in _p or 'popularity' in _p or 'accessed' in _p:
|
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]
|
response['data']['items'] = [only_p_sums(m) for m in qs]
|
||||||
else:
|
else:
|
||||||
response['data']['items'] = [only_p(m['json']) for m in qs.values('json')]
|
response['data']['items'] = [only_p(m['json']) for m in qs.values('json')]
|
||||||
|
|
|
@ -246,6 +246,7 @@ Positions
|
||||||
qs = order_query(query['qs'], query['sort'])
|
qs = order_query(query['qs'], query['sort'])
|
||||||
qs = qs.distinct()
|
qs = qs.distinct()
|
||||||
if 'keys' in data:
|
if 'keys' in data:
|
||||||
|
qs = qs.select_realed()
|
||||||
qs = qs[query['range'][0]:query['range'][1]]
|
qs = qs[query['range'][0]:query['range'][1]]
|
||||||
response['data']['items'] = [p.json(data['keys'], request.user) for p in qs]
|
response['data']['items'] = [p.json(data['keys'], request.user) for p in qs]
|
||||||
elif 'position' in query:
|
elif 'position' in query:
|
||||||
|
|
Loading…
Reference in a new issue