Mercurial > public > sg101
diff gpp/forums/feeds.py @ 509:248dd8dd67f8
For #237, use Redis as the source of posts for the RSS feeds to hopefully eliminate some slow queries.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 07 Dec 2011 01:08:54 +0000 |
parents | 63e4682d6482 |
children |
line wrap: on
line diff
--- a/gpp/forums/feeds.py Sun Dec 04 19:53:27 2011 +0000 +++ b/gpp/forums/feeds.py Wed Dec 07 01:08:54 2011 +0000 @@ -1,11 +1,14 @@ -"""This file contains the feed class for the forums application.""" +""" +This file contains the feed class for the forums application. +""" from django.contrib.syndication.views import Feed from django.core.exceptions import ObjectDoesNotExist from django.shortcuts import get_object_or_404 from forums.models import Forum, Topic, Post from core.functions import copyright_str +from forums.latest import get_latest_posts class ForumsFeed(Feed): @@ -16,9 +19,10 @@ author_email = 'admin@surfguitar101.com' def get_object(self, request, forum_slug): - # only return public forums + if forum_slug: - forum = get_object_or_404(Forum, slug=forum_slug) + forum = Forum.objects.get(slug=forum_slug) + # only return public forums if forum.id not in Forum.objects.public_forum_ids(): raise ObjectDoesNotExist return forum @@ -52,38 +56,23 @@ return copyright_str() def items(self, obj): - if obj is None: - # return a combined feed of public forum threads - - # This was tricky to do without suffering a large performance - # impact. Because the number of forums is small, MySQL did not - # try to use an index and ended up searching all the topics for - # candidate posts. We work around this by first getting a small list - # of candidate topics, and then searching them. This is more - # queries but a *lot* more time efficient. - - forum_ids = Forum.objects.public_forum_ids() - topic_ids = list(Topic.objects.filter(forum__in=forum_ids).order_by( - '-update_date').values_list('id', flat=True)[:30]) - items = Post.objects.filter(topic__in=topic_ids) - - else: - items = Post.objects.filter(topic__forum=obj) - - return items.order_by('-creation_date').select_related('topic', 'user', - 'topic__forum')[:30] + forum_id = obj.id if obj else None + return get_latest_posts(forum_id=forum_id) def item_title(self, item): - return item.topic.name + return item['title'] def item_description(self, item): - return item.html + return item['content'] def item_author_name(self, item): - return item.user.username + return item['author'] def item_pubdate(self, item): - return item.creation_date + return item['pubdate'] def item_categories(self, item): - return (item.topic.forum.name, ) + return [item['forum_name']] + + def item_link(self, item): + return item['url']