Show More
@@ -64,6 +64,10 b' class PostManager(models.Manager):' | |||||
64 | thread.bump() |
|
64 | thread.bump() | |
65 | thread.last_edit_time = timezone.now() |
|
65 | thread.last_edit_time = timezone.now() | |
66 | thread.save() |
|
66 | thread.save() | |
|
67 | ||||
|
68 | cache_key = thread.get_cache_key | |||
|
69 | cache.delete(cache_key) | |||
|
70 | ||||
67 | else: |
|
71 | else: | |
68 | self._delete_old_threads() |
|
72 | self._delete_old_threads() | |
69 |
|
73 | |||
@@ -81,6 +85,9 b' class PostManager(models.Manager):' | |||||
81 | thread.last_edit_time = timezone.now() |
|
85 | thread.last_edit_time = timezone.now() | |
82 | thread.save() |
|
86 | thread.save() | |
83 |
|
87 | |||
|
88 | cache_key = thread.get_cache_key | |||
|
89 | cache.delete(cache_key) | |||
|
90 | ||||
84 | post.delete() |
|
91 | post.delete() | |
85 |
|
92 | |||
86 | def delete_posts_by_ip(self, ip): |
|
93 | def delete_posts_by_ip(self, ip): | |
@@ -116,10 +123,17 b' class PostManager(models.Manager):' | |||||
116 | except Post.DoesNotExist: |
|
123 | except Post.DoesNotExist: | |
117 | raise Http404 |
|
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 | if opening_post.replies: |
|
131 | if opening_post.replies: | |
120 | thread = [opening_post] |
|
132 | thread = [opening_post] | |
121 | thread.extend(opening_post.replies.all().order_by('pub_time')) |
|
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 | return thread |
|
137 | return thread | |
124 |
|
138 | |||
125 | def exists(self, post_id): |
|
139 | def exists(self, post_id): | |
@@ -303,6 +317,7 b' class Post(models.Model):' | |||||
303 | if self.can_bump(): |
|
317 | if self.can_bump(): | |
304 | self.bump_time = timezone.now() |
|
318 | self.bump_time = timezone.now() | |
305 |
|
319 | |||
|
320 | ||||
306 | def get_last_replies(self): |
|
321 | def get_last_replies(self): | |
307 | if settings.LAST_REPLIES_COUNT > 0: |
|
322 | if settings.LAST_REPLIES_COUNT > 0: | |
308 | reply_count = self.get_reply_count() |
|
323 | reply_count = self.get_reply_count() | |
@@ -320,6 +335,9 b' class Post(models.Model):' | |||||
320 |
|
335 | |||
321 | return self.tags.order_by('name') |
|
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 | class User(models.Model): |
|
342 | class User(models.Model): | |
325 |
|
343 |
General Comments 0
You need to be logged in to leave comments.
Login now