diff --git a/boards/models.py b/boards/models.py --- a/boards/models.py +++ b/boards/models.py @@ -64,6 +64,10 @@ class PostManager(models.Manager): thread.bump() thread.last_edit_time = timezone.now() thread.save() + + cache_key = thread.get_cache_key + cache.delete(cache_key) + else: self._delete_old_threads() @@ -81,6 +85,9 @@ class PostManager(models.Manager): thread.last_edit_time = timezone.now() thread.save() + cache_key = thread.get_cache_key + cache.delete(cache_key) + post.delete() def delete_posts_by_ip(self, ip): @@ -116,10 +123,17 @@ class PostManager(models.Manager): except Post.DoesNotExist: raise Http404 + cache_key = opening_post.get_cache_key() + thread = cache.get(cache_key) + if thread: + return thread + if opening_post.replies: thread = [opening_post] thread.extend(opening_post.replies.all().order_by('pub_time')) + cache.set(cache_key, thread, board_settings.CACHE_TIMEOUT) + return thread def exists(self, post_id): @@ -303,6 +317,7 @@ class Post(models.Model): if self.can_bump(): self.bump_time = timezone.now() + def get_last_replies(self): if settings.LAST_REPLIES_COUNT > 0: reply_count = self.get_reply_count() @@ -320,6 +335,9 @@ class Post(models.Model): return self.tags.order_by('name') + def get_cache_key(self): + return str(self.id) + str(self.last_edit_time) + class User(models.Model):