Show More
@@ -23,7 +23,7 b" APP_LABEL_BOARDS = 'boards'" | |||||
23 |
|
23 | |||
24 | CACHE_KEY_PPD = 'ppd' |
|
24 | CACHE_KEY_PPD = 'ppd' | |
25 | CACHE_KEY_POST_URL = 'post_url' |
|
25 | CACHE_KEY_POST_URL = 'post_url' | |
26 | CACHE_KEY_OPENING_POST = 'opening_post' |
|
26 | CACHE_KEY_OPENING_POST = 'opening_post_id' | |
27 |
|
27 | |||
28 | POSTS_PER_DAY_RANGE = range(7) |
|
28 | POSTS_PER_DAY_RANGE = range(7) | |
29 |
|
29 | |||
@@ -253,7 +253,7 b' class Post(models.Model):' | |||||
253 | return self.referenced_posts.exists() |
|
253 | return self.referenced_posts.exists() | |
254 |
|
254 | |||
255 | def is_opening(self): |
|
255 | def is_opening(self): | |
256 | return self.get_thread().get_opening_post() == self |
|
256 | return self.get_thread().get_opening_post_id() == self.id | |
257 |
|
257 | |||
258 | def save(self, *args, **kwargs): |
|
258 | def save(self, *args, **kwargs): | |
259 | """ |
|
259 | """ | |
@@ -418,14 +418,19 b' class Thread(models.Model):' | |||||
418 | Get first post of the thread |
|
418 | Get first post of the thread | |
419 | """ |
|
419 | """ | |
420 |
|
420 | |||
421 | # cache_key = CACHE_KEY_OPENING_POST + str(self.id) |
|
|||
422 | # opening_post = cache.get(cache_key) |
|
|||
423 | # if not opening_post: |
|
|||
424 | opening_post = self.get_replies()[0] |
|
421 | opening_post = self.get_replies()[0] | |
425 | # cache.set(cache_key, opening_post) |
|
|||
426 |
|
422 | |||
427 | return opening_post |
|
423 | return opening_post | |
428 |
|
424 | |||
|
425 | def get_opening_post_id(self): | |||
|
426 | cache_key = CACHE_KEY_OPENING_POST + str(self.id) | |||
|
427 | opening_post_id = cache.get(cache_key) | |||
|
428 | if not opening_post_id: | |||
|
429 | opening_post_id = self.get_replies()[0].id | |||
|
430 | cache.set(cache_key, opening_post_id) | |||
|
431 | ||||
|
432 | return opening_post_id | |||
|
433 | ||||
429 | def __unicode__(self): |
|
434 | def __unicode__(self): | |
430 | return str(self.id) |
|
435 | return str(self.id) | |
431 |
|
436 |
General Comments 0
You need to be logged in to leave comments.
Login now