##// END OF EJS Templates
Added cache for thread opening post
neko259 -
r593:0e05549a default
parent child Browse files
Show More
@@ -25,6 +25,7 b" APP_LABEL_BOARDS = 'boards'"
25
25
26 CACHE_KEY_PPD = 'ppd'
26 CACHE_KEY_PPD = 'ppd'
27 CACHE_KEY_POST_URL = 'post_url'
27 CACHE_KEY_POST_URL = 'post_url'
28 CACHE_KEY_OPENING_POST = 'opening_post'
28
29
29 POSTS_PER_DAY_RANGE = range(7)
30 POSTS_PER_DAY_RANGE = range(7)
30
31
@@ -271,7 +272,7 b' class Post(models.Model):'
271 return self.referenced_posts.all().exists()
272 return self.referenced_posts.all().exists()
272
273
273 def is_opening(self):
274 def is_opening(self):
274 return self.thread_new.get_replies()[0] == self
275 return self.thread_new.get_opening_post() == self
275
276
276 def save(self, *args, **kwargs):
277 def save(self, *args, **kwargs):
277 """
278 """
@@ -430,7 +431,13 b' class Thread(models.Model):'
430 Get first post of the thread
431 Get first post of the thread
431 """
432 """
432
433
433 return self.get_replies()[0]
434 cache_key = CACHE_KEY_OPENING_POST + str(self.id)
435 opening_post = cache.get(cache_key)
436 if not opening_post:
437 opening_post = self.get_replies()[0]
438 cache.set(cache_key, opening_post)
439
440 return opening_post
434
441
435 def __unicode__(self):
442 def __unicode__(self):
436 return str(self.id)
443 return str(self.id)
General Comments 0
You need to be logged in to leave comments. Login now