try and fail to reduce queries on homepage

This commit is contained in:
Glen Chiacchieri 2013-07-24 19:01:26 +00:00
parent 98ad2a4dc9
commit 2db792eec1
2 changed files with 3 additions and 5 deletions

View file

@ -146,14 +146,14 @@ def forum_unreads(forum, user):
return False
else:
if isinstance(user.posttracking.topics, dict):
topics = forum.topics.all().only('last_post')
topics = forum.topics.only('last_post')
if user.posttracking.last_read:
topics = topics.filter(updated__gte=user.posttracking.last_read)
for topic in topics:
if topic.last_post_id > user.posttracking.topics.get(str(topic.id), 0):
return True
elif user.posttracking.last_read:
if forum.topics.all().filter(updated__gte=user.posttracking.last_read).exists():
if forum.topics.filter(updated__gte=user.posttracking.last_read).exists():
return True
else:
return True

View file

@ -45,14 +45,12 @@ def index(request, full=True):
if online_truncated:
users_online = users_online[:forum_settings.MAX_ONLINE]
_forums = Forum.objects.all()
_forums = Forum.objects.select_related('last_post__topic', 'last_post__user', 'category')
user = request.user
if not user.is_superuser:
user_groups = user.groups.all() or [] # need 'or []' for anonymous user otherwise: 'EmptyManager' object is not iterable
_forums = _forums.filter(Q(category__groups__in=user_groups) | Q(category__groups__isnull=True))
_forums = _forums.select_related('last_post__topic', 'last_post__user', 'category')
cats = {}
forums = {}
for forum in _forums: