diff gpp/news/views.py @ 197:2baadae33f2e

Got autocomplete working for the member search. Updated django and ran into a bug where url tags with comma separated kwargs starting consuming tons of CPU throughput. The work-around is to cut over to using spaces between arguments. This is now allowed to be consistent with other tags. Did some query optimization for the news app.
author Brian Neal <bgneal@gmail.com>
date Sat, 10 Apr 2010 04:32:24 +0000
parents 62eb9cbbcffc
children b4305e18d3af
line wrap: on
line diff
--- a/gpp/news/views.py	Wed Apr 07 01:59:09 2010 +0000
+++ b/gpp/news/views.py	Sat Apr 10 04:32:24 2010 +0000
@@ -40,7 +40,7 @@
 #######################################################################
 
 def index(request, page=1):
-   stories = Story.objects.all()
+   stories = Story.objects.all().select_related()
    paginator = create_paginator(stories)
    try:
       the_page = paginator.page(int(page))
@@ -87,10 +87,10 @@
 #######################################################################
 
 def category_index(request):
-   categories = Category.objects.all()
+   categories = Category.objects.all().select_related()
    cat_list = []
    for cat in categories:
-      cat_list.append((cat, cat.story_set.all()[:10]))
+      cat_list.append((cat, cat.story_set.defer('tags')[:10]))
 
    return render_to_response('news/category_index.html', {
       'cat_list': cat_list, 
@@ -215,7 +215,7 @@
 
 def tag(request, tag_name, page=1):
    tag = get_object_or_404(Tag, name=tag_name)
-   stories = TaggedItem.objects.get_by_model(Story, tag)
+   stories = TaggedItem.objects.get_by_model(Story.objects.all().select_related(), tag)
    paginator = create_paginator(stories)
    try:
       the_page = paginator.page(int(page))
@@ -227,7 +227,7 @@
       'page': the_page,
       'search_form': SearchNewsForm(),
       }, 
-      context_instance = RequestContext(request))
+      context_instance=RequestContext(request))
 
 #######################################################################