Show More
@@ -2,6 +2,7 b' import logging' | |||||
2 | import re |
|
2 | import re | |
3 | import uuid |
|
3 | import uuid | |
4 |
|
4 | |||
|
5 | from boards.utils import cached_result, datetime_to_epoch | |||
5 | from django.core.exceptions import ObjectDoesNotExist |
|
6 | from django.core.exceptions import ObjectDoesNotExist | |
6 | from django.core.urlresolvers import reverse |
|
7 | from django.core.urlresolvers import reverse | |
7 | from django.db import models |
|
8 | from django.db import models | |
@@ -107,11 +108,6 b' class Post(models.Model, Viewable):' | |||||
107 | def __str__(self): |
|
108 | def __str__(self): | |
108 | return 'P#{}/{}'.format(self.id, self.get_title()) |
|
109 | return 'P#{}/{}'.format(self.id, self.get_title()) | |
109 |
|
110 | |||
110 | def get_referenced_posts(self): |
|
|||
111 | threads = self.get_threads().all() |
|
|||
112 | return self.referenced_posts.filter(threads__in=threads)\ |
|
|||
113 | .order_by('pub_time').distinct().all() |
|
|||
114 |
|
||||
115 | def get_title(self) -> str: |
|
111 | def get_title(self) -> str: | |
116 | return self.title |
|
112 | return self.title | |
117 |
|
113 | |||
@@ -176,6 +172,13 b' class Post(models.Model, Viewable):' | |||||
176 |
|
172 | |||
177 | return self.threads |
|
173 | return self.threads | |
178 |
|
174 | |||
|
175 | def _get_cache_key(self): | |||
|
176 | return [datetime_to_epoch(self.last_edit_time)] | |||
|
177 | ||||
|
178 | @cached_result(key_method=_get_cache_key) | |||
|
179 | def get_thread_count(self): | |||
|
180 | return self.get_threads().count() | |||
|
181 | ||||
179 | def get_view(self, *args, **kwargs) -> str: |
|
182 | def get_view(self, *args, **kwargs) -> str: | |
180 | """ |
|
183 | """ | |
181 | Renders post's HTML view. Some of the post params can be passed over |
|
184 | Renders post's HTML view. Some of the post params can be passed over | |
@@ -312,7 +315,7 b' class Post(models.Model, Viewable):' | |||||
312 | ID. |
|
315 | ID. | |
313 | """ |
|
316 | """ | |
314 |
|
317 | |||
315 |
if self.get_thread |
|
318 | if self.get_thread_count() > 1: | |
316 | return '{}/{}'.format(self.get_thread().get_opening_post_id(), self.id) |
|
319 | return '{}/{}'.format(self.get_thread().get_opening_post_id(), self.id) | |
317 | else: |
|
320 | else: | |
318 | return str(self.id) |
|
321 | return str(self.id) |
@@ -181,7 +181,7 b' class Thread(models.Model):' | |||||
181 | """ |
|
181 | """ | |
182 |
|
182 | |||
183 | query = self.multi_replies.order_by('pub_time').prefetch_related( |
|
183 | query = self.multi_replies.order_by('pub_time').prefetch_related( | |
184 |
'images', 'thread', ' |
|
184 | 'images', 'thread', 'attachments') | |
185 | if view_fields_only: |
|
185 | if view_fields_only: | |
186 | query = query.defer('poster_ip') |
|
186 | query = query.defer('poster_ip') | |
187 | return query |
|
187 | return query |
General Comments 0
You need to be logged in to leave comments.
Login now