Optimize the user_view view, slashing the render time in half

This commit is contained in:
2010-10-18 16:09:25 +01:00
parent ad86c14ca0
commit b4ab0e40e1
2 changed files with 4 additions and 18 deletions

View File

@@ -279,23 +279,9 @@ def user_view(request, username=None):
profile = user.get_profile() profile = user.get_profile()
is_admin = request.user.is_staff is_admin = request.user.is_staff
if is_admin: if is_admin:
try: services = ServiceAccount.objects.select_related('service').filter(user=user).only('service__name', 'service_uid', 'active')
services = ServiceAccount.objects.filter(user=user).all() reddits = RedditAccount.objects.filter(user=user).all()
except ServiceAccount.DoesNotExist: characters = EVEPlayerCharacter.objects.select_related('corporation').filter(eveaccount__user=user).only('id', 'name', 'corporation__name')
services = None
try:
reddits = RedditAccount.objects.filter(user=user).all()
except ServiceAccount.DoesNotExist:
reddits = None
try:
eveaccounts = EVEAccount.objects.filter(user=user).all()
characters = []
for acc in eveaccounts:
chars = acc.characters.all()
for char in chars:
characters.append({'id': char.id, 'name': char.name, 'corp': char.corporation.name})
except EVEAccount.DoesNotExist:
eveaccounts = None
return render_to_response('sso/lookup/user.html', locals(), context_instance=RequestContext(request)) return render_to_response('sso/lookup/user.html', locals(), context_instance=RequestContext(request))

View File

@@ -57,7 +57,7 @@
<tr><th>Character Name</th><th>Corp</th></tr> <tr><th>Character Name</th><th>Corp</th></tr>
{% for char in characters %} {% for char in characters %}
<tr><td><a href="{% url sso.views.characters char.id %}">{{ char.name }}</a></td> <tr><td><a href="{% url sso.views.characters char.id %}">{{ char.name }}</a></td>
<td>{{ char.corp }}</td> <td>{{ char.corporation }}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>