Show More
@@ -1,4 +1,5 b'' | |||||
1 | from boards.models import Tag |
|
1 | from boards.models import Tag | |
|
2 | from boards.models.thread import FAV_THREAD_NO_UPDATES | |||
2 |
|
3 | |||
3 | MAX_TRIPCODE_COLLISIONS = 50 |
|
4 | MAX_TRIPCODE_COLLISIONS = 50 | |
4 |
|
5 | |||
@@ -19,8 +20,6 b" SETTING_LAST_NOTIFICATION_ID = 'last_not" | |||||
19 | SETTING_IMAGE_VIEWER = 'image_viewer' |
|
20 | SETTING_IMAGE_VIEWER = 'image_viewer' | |
20 | SETTING_TRIPCODE = 'tripcode' |
|
21 | SETTING_TRIPCODE = 'tripcode' | |
21 |
|
22 | |||
22 | FAV_THREAD_NO_UPDATES = -1 |
|
|||
23 |
|
||||
24 | DEFAULT_THEME = 'md' |
|
23 | DEFAULT_THEME = 'md' | |
25 |
|
24 | |||
26 |
|
25 |
@@ -11,6 +11,8 b' from boards.utils import cached_result, ' | |||||
11 | from boards.models.post import Post |
|
11 | from boards.models.post import Post | |
12 | from boards.models.tag import Tag |
|
12 | from boards.models.tag import Tag | |
13 |
|
13 | |||
|
14 | FAV_THREAD_NO_UPDATES = -1 | |||
|
15 | ||||
14 |
|
16 | |||
15 | __author__ = 'neko259' |
|
17 | __author__ = 'neko259' | |
16 |
|
18 | |||
@@ -58,14 +60,16 b' class ThreadManager(models.Manager):' | |||||
58 | query = None |
|
60 | query = None | |
59 | # TODO Use classes instead of dicts |
|
61 | # TODO Use classes instead of dicts | |
60 | for data in datas: |
|
62 | for data in datas: | |
61 | q = (Q(id=data['op'].get_thread().id) |
|
63 | if data['last_id'] != FAV_THREAD_NO_UPDATES: | |
62 |
|
|
64 | q = (Q(id=data['op'].get_thread().id) | |
63 | if query is None: |
|
65 | & Q(multi_replies__id__gt=data['last_id'])) | |
64 |
query |
|
66 | if query is None: | |
65 | else: |
|
67 | query = q | |
66 |
|
|
68 | else: | |
67 | return self.filter(query).annotate( |
|
69 | query = query | q | |
68 | new_post_count=Count('multi_replies')) |
|
70 | if query is not None: | |
|
71 | return self.filter(query).annotate( | |||
|
72 | new_post_count=Count('multi_replies')) | |||
69 |
|
73 | |||
70 | def get_new_post_count(self, datas): |
|
74 | def get_new_post_count(self, datas): | |
71 | return self.get_new_posts(datas).aggregate( |
|
75 | return self.get_new_posts(datas).aggregate( |
@@ -259,16 +259,21 b' def api_get_new_posts(request):' | |||||
259 | ops = [{'op': op, 'last_id': fav_threads[str(op.id)]} for op in fav_thread_ops] |
|
259 | ops = [{'op': op, 'last_id': fav_threads[str(op.id)]} for op in fav_thread_ops] | |
260 | if include_posts: |
|
260 | if include_posts: | |
261 | new_post_threads = Thread.objects.get_new_posts(ops) |
|
261 | new_post_threads = Thread.objects.get_new_posts(ops) | |
262 | thread_ids = {thread.id: thread for thread in new_post_threads} |
|
262 | if new_post_threads: | |
|
263 | thread_ids = {thread.id: thread for thread in new_post_threads} | |||
|
264 | else: | |||
|
265 | thread_ids = dict() | |||
263 |
|
266 | |||
264 | for op in fav_thread_ops: |
|
267 | for op in fav_thread_ops: | |
265 | fav_thread_dict = dict() |
|
268 | fav_thread_dict = dict() | |
266 |
|
269 | |||
267 |
|
|
270 | op_thread = op.get_thread() | |
268 |
|
|
271 | if op_thread.id in thread_ids: | |
|
272 | thread = thread_ids[op_thread.id] | |||
269 | new_post_count = thread.new_post_count |
|
273 | new_post_count = thread.new_post_count | |
270 |
fav_thread_dict['newest_post_link'] = thread. |
|
274 | fav_thread_dict['newest_post_link'] = thread.get_replies()\ | |
271 | .first().get_absolute_url() |
|
275 | .filter(id__gt=fav_threads[str(op.id)])\ | |
|
276 | .first().get_absolute_url() | |||
272 | else: |
|
277 | else: | |
273 | new_post_count = 0 |
|
278 | new_post_count = 0 | |
274 | fav_thread_dict['new_post_count'] = new_post_count |
|
279 | fav_thread_dict['new_post_count'] = new_post_count |
General Comments 0
You need to be logged in to leave comments.
Login now