# HG changeset patch # User Brian Neal # Date 1296333276 0 # Node ID 03b70aa5c872ec73728907388dac5d8081723db4 # Parent 377dd359636f4e6a1951926ed99251f17f12ed77 The home page was taking 27 seconds to load; 99% of the time was being spent in the new_posts template tag query. Reworked it a bit to be much more sane. diff -r 377dd359636f -r 03b70aa5c872 gpp/forums/templatetags/forum_tags.py --- a/gpp/forums/templatetags/forum_tags.py Thu Jan 27 03:00:16 2011 +0000 +++ b/gpp/forums/templatetags/forum_tags.py Sat Jan 29 20:34:36 2011 +0000 @@ -12,6 +12,7 @@ from forums.models import Forum from forums.models import Topic from forums.models import Post +from forums.models import Category from core.models import Statistic @@ -119,10 +120,26 @@ This tag displays the topics that have the newest posts. Only the "public" forums are displayed. """ - topics = Topic.objects.filter( - forum__category__groups__isnull=True).select_related( + public_forums = cache.get('public_forum_ids') + if public_forums is None: + public_forums = list(Forum.objects.filter( + category__groups__isnull=True).values_list('id', flat=True)) + cache.set('public_forum_ids', public_forums, 10 * 60) + + topics = Topic.objects.filter(forum__in=public_forums).select_related( 'user', 'last_post').order_by('-update_date')[:10] + # 1: + #public_cats = list(Category.objects.filter(groups__isnull=True).values_list('id', flat=True)) + #topics = Topic.objects.filter( + # forum__category__in=public_cats).select_related( + # 'user', 'last_post').order_by('-update_date')[:10] + + # 0: + #topics = Topic.objects.filter( + # forum__category__groups__isnull=True).select_related( + # 'user', 'last_post').order_by('-update_date')[:10] + return { 'topics': topics, 'user': context['user'],