# HG changeset patch # User neko259 # Date 2014-06-16 12:01:25 # Node ID 597b8a7d40ee671cfac51d103bed96aad0fcb4c3 # Parent 641dff39489e6a301fd243c87fe3a8034f15a175 Optimized loading post images in post template diff --git a/boards/models/thread.py b/boards/models/thread.py --- a/boards/models/thread.py +++ b/boards/models/thread.py @@ -87,8 +87,7 @@ class Thread(models.Model): if reply_count > 0: reply_count_to_show = min(settings.LAST_REPLIES_COUNT, reply_count - 1) - replies = self.replies.order_by('pub_time').defer( - 'poster_user_agent', 'text_markup_type') + replies = self.get_replies() last_replies = replies[reply_count - reply_count_to_show:] return last_replies @@ -107,7 +106,7 @@ class Thread(models.Model): Gets sorted thread posts """ - query = self.replies.order_by('pub_time') + query = self.replies.order_by('pub_time').prefetch_related('images') if view_fields_only: query = query.defer('poster_user_agent', 'text_markup_type') return query.all() @@ -161,4 +160,4 @@ class Thread(models.Model): Gets opening post's pub time because thread does not have its own one. """ - return self.get_opening_post().pub_time \ No newline at end of file + return self.get_opening_post().pub_time 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 @@ -47,7 +47,7 @@ {% endif %} {% if post.images.exists %} - {% with post.get_first_image as image %} + {% with post.images.all.0 as image %}