# HG changeset patch # User neko259 # Date 2013-10-28 18:55:22 # Node ID eebfca22741b708676ebb5acb853d7ec87209de9 # Parent 413c40ad47c32f960ba7571a09fda0c641863d6f Use cache for thread list. diff --git a/boards/models.py b/boards/models.py --- a/boards/models.py +++ b/boards/models.py @@ -65,7 +65,7 @@ class PostManager(models.Manager): else: self._delete_old_threads() - self.connect_replies(post) + self.connect_replies(post) return post @@ -100,7 +100,7 @@ class PostManager(models.Manager): if page != ALL_PAGES: thread_count = threads.count() - if page < self.get_thread_page_count(tag=tag): + if page < self._get_page_count(thread_count): start_thread = page * settings.THREADS_PER_PAGE end_thread = min(start_thread + settings.THREADS_PER_PAGE, thread_count) @@ -131,8 +131,7 @@ class PostManager(models.Manager): else: threads = self.filter(thread=None) - return int(math.ceil(threads.count() / float( - settings.THREADS_PER_PAGE))) + return self._get_page_count(threads.count()) def _delete_old_threads(self): """ @@ -154,13 +153,16 @@ class PostManager(models.Manager): map(self.delete_post, old_threads) def connect_replies(self, post): - """Connect replies to a post to show them as a refmap""" + """Connect replies to a post to show them as a refmap""" - for reply_number in re.finditer(REGEX_REPLY, post.text.raw): - id = reply_number.group(1) - ref_post = self.filter(id=id) - if ref_post.count() > 0: - ref_post[0].referenced_posts.add(post) + for reply_number in re.finditer(REGEX_REPLY, post.text.raw): + id = reply_number.group(1) + ref_post = self.filter(id=id) + if ref_post.count() > 0: + ref_post[0].referenced_posts.add(post) + + def _get_page_count(self, thread_count): + return int(math.ceil(thread_count / float(settings.THREADS_PER_PAGE))) class TagManager(models.Manager): diff --git a/boards/templates/boards/posting_general.html b/boards/templates/boards/posting_general.html --- a/boards/templates/boards/posting_general.html +++ b/boards/templates/boards/posting_general.html @@ -14,6 +14,8 @@ {% block content %} + {% get_current_language as LANGUAGE_CODE %} + {% if tag %}

@@ -31,6 +33,7 @@ {% if threads %} {% for thread in threads %} + {% cache 600 thread_short thread.thread.last_edit_time moderator LANGUAGE_CODE %}
{% if thread.bumpable %}
@@ -93,9 +96,9 @@ {% endif %}
- {% if thread.thread.get_last_replies.exists %} + {% if thread.last_replies.exists %}
- {% for post in thread.thread.get_last_replies %} + {% for post in thread.last_replies %} {% if thread.bumpable %}
{% else %} @@ -137,6 +140,7 @@
{% endif %}
+ {% endcache %} {% endfor %} {% else %}
diff --git a/boards/views.py b/boards/views.py --- a/boards/views.py +++ b/boards/views.py @@ -47,8 +47,11 @@ def index(request, page=0): threads = [] for thread in Post.objects.get_threads(page=int(page)): - threads.append({'thread': thread, - 'bumpable': thread.can_bump()}) + threads.append({ + 'thread': thread, + 'bumpable': thread.can_bump(), + 'last_replies': thread.get_last_replies(), + }) context['threads'] = None if len(threads) == 0 else threads context['form'] = form @@ -121,8 +124,11 @@ def tag(request, tag_name, page=0): tag = get_object_or_404(Tag, name=tag_name) threads = [] for thread in Post.objects.get_threads(tag=tag, page=int(page)): - threads.append({'thread': thread, - 'bumpable': thread.can_bump()}) + threads.append({ + 'thread': thread, + 'bumpable': thread.can_bump(), + 'last_replies': thread.get_last_replies(), + }) if request.method == 'POST': form = ThreadForm(request.POST, request.FILES,