##// END OF EJS Templates
Readded post cache
neko259 -
r394:f878102e default
parent child Browse files
Show More
@@ -3,6 +3,7 b' from random import random'
3 3 import time
4 4 import math
5 5 import re
6 from django.core.cache import cache
6 7
7 8 from django.db import models
8 9 from django.http import Http404
@@ -10,6 +11,7 b' from django.utils import timezone'
10 11 from markupfield.fields import MarkupField
11 12
12 13 from neboard import settings
14 from boards import settings as boards_settings
13 15 from boards import thumbs
14 16
15 17 BAN_REASON_AUTO = 'Auto'
@@ -66,10 +68,6 b' class PostManager(models.Manager):'
66 68 thread.bump()
67 69 thread.last_edit_time = posting_time
68 70 thread.save()
69
70 #cache_key = thread.get_cache_key()
71 #cache.delete(cache_key)
72
73 71 else:
74 72 self._delete_old_threads()
75 73
@@ -84,12 +82,12 b' class PostManager(models.Manager):'
84 82 # Update thread's last edit time (used as cache key)
85 83 thread = post.thread
86 84 if thread:
85 thread.clear_cache()
86
87 87 thread.last_edit_time = timezone.now()
88 88 thread.save()
89 89
90 #cache_key = thread.get_cache_key()
91 #cache.delete(cache_key)
92
90 post.clear_cache()
93 91 post.delete()
94 92
95 93 def delete_posts_by_ip(self, ip):
@@ -125,16 +123,16 b' class PostManager(models.Manager):'
125 123 except Post.DoesNotExist:
126 124 raise Http404
127 125
128 #cache_key = opening_post.get_cache_key()
129 #thread = cache.get(cache_key)
130 #if thread:
131 # return thread
126 cache_key = opening_post.get_cache_key()
127 thread = cache.get(cache_key)
128 if thread:
129 return thread
132 130
133 131 if opening_post.replies:
134 132 thread = [opening_post]
135 133 thread.extend(opening_post.replies.all().order_by('pub_time'))
136 134
137 #cache.set(cache_key, thread, board_settings.CACHE_TIMEOUT)
135 cache.set(cache_key, thread, boards_settings.CACHE_TIMEOUT)
138 136
139 137 return thread
140 138
@@ -260,12 +258,20 b' class Post(models.Model):'
260 258
261 259 return post_count <= settings.MAX_POSTS_PER_THREAD
262 260
261 def clear_cache(self):
262 """Remove the post from cache"""
263
264 cache_key = self.get_cache_key()
265 cache.delete(cache_key)
266
263 267 def bump(self):
264 268 """Bump (move to up) thread"""
265 269
266 270 if self.can_bump():
267 271 self.bump_time = timezone.now()
268 272
273 self.clear_cache()
274
269 275 def get_last_replies(self):
270 276 if settings.LAST_REPLIES_COUNT > 0:
271 277 reply_count = self.get_reply_count()
@@ -284,12 +290,10 b' class Post(models.Model):'
284 290 return self.tags.order_by('name')
285 291
286 292 def get_cache_key(self):
287 return str(self.id) + str(self.last_edit_time.microsecond)
293 return 'thread_cache' + str(self.id)
288 294
289 295 def get_sorted_referenced_posts(self):
290 296 return self.referenced_posts.order_by('id')
291 297
292 298 def is_referenced(self):
293 299 return self.referenced_posts.count() > 0
294
295
General Comments 0
You need to be logged in to leave comments. Login now