diff --git a/boards/models/post.py b/boards/models/post.py --- a/boards/models/post.py +++ b/boards/models/post.py @@ -237,13 +237,15 @@ class Post(models.Model): poster_ip = models.GenericIPAddressField() poster_user_agent = models.TextField() - thread_new = models.ForeignKey('Thread', null=True, default=None) + thread_new = models.ForeignKey('Thread', null=True, default=None, + db_index=True) last_edit_time = models.DateTimeField() - user = models.ForeignKey('User', null=True, default=None) + user = models.ForeignKey('User', null=True, default=None, db_index=True) referenced_posts = models.ManyToManyField('Post', symmetrical=False, null=True, - blank=True, related_name='rfp+') + blank=True, related_name='rfp+', + db_index=True) def __unicode__(self): return '#' + str(self.id) + ' ' + self.title + ' (' + \ @@ -413,8 +415,10 @@ class Thread(models.Model): reply_count_to_show = min(settings.LAST_REPLIES_COUNT, reply_count - 1) last_replies = self.replies.order_by( - 'pub_time').prefetch_related('referenced_posts')[ - reply_count - reply_count_to_show:] + 'pub_time').defer('image_hash', 'poster_user_agent', + 'text_markup_type') \ + .prefetch_related('referenced_posts')[ + reply_count - reply_count_to_show:] return last_replies @@ -435,9 +439,8 @@ class Thread(models.Model): query = self.replies.order_by('pub_time') if view_fields_only: query = query.defer( - 'image_hash', 'poster_user_agent', 'text_markup_type', - 'last_edit_time') - return query.all() + 'image_hash', 'poster_user_agent', 'text_markup_type') + return query.all().prefetch_related('referenced_posts') def add_tag(self, tag): """ diff --git a/boards/templates/boards/post.html b/boards/templates/boards/post.html --- a/boards/templates/boards/post.html +++ b/boards/templates/boards/post.html @@ -71,7 +71,7 @@ {% if post.referenced_posts.exists %}