diff --git a/boards/models/post.py b/boards/models/post.py --- a/boards/models/post.py +++ b/boards/models/post.py @@ -25,6 +25,7 @@ APP_LABEL_BOARDS = 'boards' CACHE_KEY_PPD = 'ppd' CACHE_KEY_POST_URL = 'post_url' +CACHE_KEY_OPENING_POST = 'opening_post' POSTS_PER_DAY_RANGE = range(7) @@ -271,7 +272,7 @@ class Post(models.Model): return self.referenced_posts.all().exists() def is_opening(self): - return self.thread_new.get_replies()[0] == self + return self.thread_new.get_opening_post() == self def save(self, *args, **kwargs): """ @@ -430,7 +431,13 @@ class Thread(models.Model): Get first post of the thread """ - return self.get_replies()[0] + cache_key = CACHE_KEY_OPENING_POST + str(self.id) + opening_post = cache.get(cache_key) + if not opening_post: + opening_post = self.get_replies()[0] + cache.set(cache_key, opening_post) + + return opening_post def __unicode__(self): return str(self.id)