Mercurial > public > sg101
comparison gpp/forums/views/main.py @ 522:82b97697312e
Created Celery tasks to process new posts and topics. Keep the updated topic set in Redis.
This is for tickets #194, #237, #239.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 18 Dec 2011 23:46:52 +0000 |
parents | 3b30286adba5 |
children | 7388cdf61b25 |
comparison
equal
deleted
inserted
replaced
521:dd14ab08a9c4 | 522:82b97697312e |
---|---|
36 | 36 |
37 from forums.attachments import AttachmentProcessor | 37 from forums.attachments import AttachmentProcessor |
38 import forums.permissions as perms | 38 import forums.permissions as perms |
39 from forums.signals import (notify_new_topic, notify_updated_topic, | 39 from forums.signals import (notify_new_topic, notify_updated_topic, |
40 notify_new_post, notify_updated_post) | 40 notify_new_post, notify_updated_post) |
41 from forums.latest import get_latest_topic_ids | |
41 | 42 |
42 ####################################################################### | 43 ####################################################################### |
43 | 44 |
44 TOPICS_PER_PAGE = 50 | 45 TOPICS_PER_PAGE = 50 |
45 POSTS_PER_PAGE = 20 | 46 POSTS_PER_PAGE = 20 |
877 """Displays the last num topics that have been posted to.""" | 878 """Displays the last num topics that have been posted to.""" |
878 | 879 |
879 # sanity check num | 880 # sanity check num |
880 num = min(50, max(10, int(num))) | 881 num = min(50, max(10, int(num))) |
881 | 882 |
882 public_forum_ids = Forum.objects.public_forum_ids() | |
883 | |
884 # MySQL didn't do this query very well unfortunately... | 883 # MySQL didn't do this query very well unfortunately... |
884 # | |
885 #public_forum_ids = Forum.objects.public_forum_ids() | |
885 #topics = Topic.objects.filter(forum__in=public_forum_ids).select_related( | 886 #topics = Topic.objects.filter(forum__in=public_forum_ids).select_related( |
886 # 'forum', 'user', 'last_post', 'last_post__user').order_by( | 887 # 'forum', 'user', 'last_post', 'last_post__user').order_by( |
887 # '-update_date')[:num] | 888 # '-update_date')[:num] |
888 topic_ids = list(Topic.objects.filter(forum__in=public_forum_ids).order_by( | 889 |
889 '-update_date').values_list('id', flat=True)[:num]) | 890 # Save 1 query by using forums.latest to give us a list of the most recent |
891 # topics; forums.latest doesn't save enough info to give us everything we | |
892 # need so we hit the database for the rest. | |
893 | |
894 topic_ids = get_latest_topic_ids(num) | |
890 topics = Topic.objects.filter(id__in=topic_ids).select_related( | 895 topics = Topic.objects.filter(id__in=topic_ids).select_related( |
891 'forum', 'user', 'last_post', 'last_post__user').order_by( | 896 'forum', 'user', 'last_post', 'last_post__user').order_by( |
892 '-update_date')[:num] | 897 '-update_date') |
893 | 898 |
894 paginator = create_topic_paginator(topics) | 899 paginator = create_topic_paginator(topics) |
895 page_num = get_page_num(request) | 900 page_num = get_page_num(request) |
896 try: | 901 try: |
897 page = paginator.page(page_num) | 902 page = paginator.page(page_num) |