# HG changeset patch # User neko259 # Date 2013-09-10 17:57:54 # Node ID cc12beaafca2acd1e3484c7369bc621803c50a7b # Parent bc8fce57a613175450b8b6d933cdd85f22c04658 Optimized thread view a lot. diff --git a/boards/models.py b/boards/models.py --- a/boards/models.py +++ b/boards/models.py @@ -246,7 +246,9 @@ class Post(models.Model): def get_images_count(self): images_count = 1 if self.image else 0 - for reply in self._get_replies(): + + replies = self._get_replies() + for reply in replies: if reply.image: images_count += 1 @@ -255,7 +257,7 @@ class Post(models.Model): def can_bump(self): """Check if the thread can be bumped by replying""" - replies_count = len(Post.objects.get_thread(self.id)) + replies_count = self.get_reply_count() + 1 return replies_count <= settings.MAX_POSTS_PER_THREAD @@ -292,13 +294,8 @@ class User(models.Model): return setting def get_setting(self, name): - settings = Setting.objects.filter(name=name, user=self) - if len(settings) > 0: - setting = settings[0] - else: - setting = None - - if setting: + if Setting.objects.filter(name=name, user=self).exists(): + setting = Setting.objects.get(name=name, user=self) setting_value = setting.value else: setting_value = None 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 @@ -23,9 +23,9 @@ {% for thread in threads %}
{% if thread.can_bump %} -
+
{% else %} -
+
{% endif %} {% if thread.image %}