##// END OF EJS Templates
Cache threads
neko259 -
r324:c419aa11 default
parent child Browse files
Show More
@@ -64,6 +64,10 b' class PostManager(models.Manager):'
64 64 thread.bump()
65 65 thread.last_edit_time = timezone.now()
66 66 thread.save()
67
68 cache_key = thread.get_cache_key
69 cache.delete(cache_key)
70
67 71 else:
68 72 self._delete_old_threads()
69 73
@@ -81,6 +85,9 b' class PostManager(models.Manager):'
81 85 thread.last_edit_time = timezone.now()
82 86 thread.save()
83 87
88 cache_key = thread.get_cache_key
89 cache.delete(cache_key)
90
84 91 post.delete()
85 92
86 93 def delete_posts_by_ip(self, ip):
@@ -116,10 +123,17 b' class PostManager(models.Manager):'
116 123 except Post.DoesNotExist:
117 124 raise Http404
118 125
126 cache_key = opening_post.get_cache_key()
127 thread = cache.get(cache_key)
128 if thread:
129 return thread
130
119 131 if opening_post.replies:
120 132 thread = [opening_post]
121 133 thread.extend(opening_post.replies.all().order_by('pub_time'))
122 134
135 cache.set(cache_key, thread, board_settings.CACHE_TIMEOUT)
136
123 137 return thread
124 138
125 139 def exists(self, post_id):
@@ -303,6 +317,7 b' class Post(models.Model):'
303 317 if self.can_bump():
304 318 self.bump_time = timezone.now()
305 319
320
306 321 def get_last_replies(self):
307 322 if settings.LAST_REPLIES_COUNT > 0:
308 323 reply_count = self.get_reply_count()
@@ -320,6 +335,9 b' class Post(models.Model):'
320 335
321 336 return self.tags.order_by('name')
322 337
338 def get_cache_key(self):
339 return str(self.id) + str(self.last_edit_time)
340
323 341
324 342 class User(models.Model):
325 343
General Comments 0
You need to be logged in to leave comments. Login now