# HG changeset patch # User neko259 # Date 2013-11-21 14:32:36 # Node ID 0d260248a771915843c8bc12d525971e8dd54a2a # Parent f18b32bdfe3c95c53023d9f225dd026b3bbf6e40 Removed strange 'exists' method in post manager, fixed tests in which it was used diff --git a/boards/models/post.py b/boards/models/post.py --- a/boards/models/post.py +++ b/boards/models/post.py @@ -3,7 +3,6 @@ from random import random import time import math import re -from django.core.cache import cache from django.db import models from django.http import Http404 @@ -79,15 +78,12 @@ class PostManager(models.Manager): if post.replies.count() > 0: map(self.delete_post, post.replies.all()) - # Update thread's last edit time (used as cache key) + # Update thread's last edit time thread = post.thread if thread: - thread.clear_cache() - thread.last_edit_time = timezone.now() thread.save() - post.clear_cache() post.delete() def delete_posts_by_ip(self, ip): @@ -123,17 +119,10 @@ 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, boards_settings.CACHE_TIMEOUT) - return thread def get_thread_page_count(self, tag=None): @@ -253,20 +242,12 @@ class Post(models.Model): return post_count <= settings.MAX_POSTS_PER_THREAD - def clear_cache(self): - """Remove the post from cache""" - - cache_key = self.get_cache_key() - cache.delete(cache_key) - def bump(self): """Bump (move to up) thread""" if self.can_bump(): self.bump_time = timezone.now() - self.clear_cache() - def get_last_replies(self): if settings.LAST_REPLIES_COUNT > 0: reply_count = self.get_reply_count() @@ -284,9 +265,6 @@ class Post(models.Model): return self.tags.order_by('name') - def get_cache_key(self): - return 'thread_cache' + str(self.id) - def get_sorted_referenced_posts(self): return self.referenced_posts.order_by('id') diff --git a/boards/tests.py b/boards/tests.py --- a/boards/tests.py +++ b/boards/tests.py @@ -41,7 +41,7 @@ class PostTests(TestCase): Post.objects.delete_post(post) - self.assertFalse(Post.objects.exists(post_id)) + self.assertFalse(Post.objects.filter(id=post_id).exists()) def test_delete_thread(self): """Test thread deletion""" @@ -51,7 +51,7 @@ class PostTests(TestCase): Post.objects.delete_post(thread) - self.assertFalse(Post.objects.exists(reply.id)) + self.assertFalse(Post.objects.filter(id=reply.id).exists()) def test_post_to_thread(self): """Test adding post to a thread""" @@ -72,7 +72,7 @@ class PostTests(TestCase): Post.objects.delete_posts_by_ip('0.0.0.0') - self.assertFalse(Post.objects.exists(post_id)) + self.assertFalse(Post.objects.filter(id=post_id).exists()) def test_get_thread(self): """Test getting all posts of a thread"""