##// END OF EJS Templates
Removed unecessary connection of a thread to its replies, cause posts are...
neko259 -
r958:19177ecc default
parent child Browse files
Show More
@@ -0,0 +1,18 b''
1 # -*- coding: utf-8 -*-
2 from __future__ import unicode_literals
3
4 from django.db import models, migrations
5
6
7 class Migration(migrations.Migration):
8
9 dependencies = [
10 ('boards', '0004_tag_required'),
11 ]
12
13 operations = [
14 migrations.RemoveField(
15 model_name='thread',
16 name='replies',
17 ),
18 ]
@@ -14,7 +14,6 b' from boards import settings'
14 from boards.mdx_neboard import bbcode_extended
14 from boards.mdx_neboard import bbcode_extended
15 from boards.models import PostImage
15 from boards.models import PostImage
16 from boards.models.base import Viewable
16 from boards.models.base import Viewable
17 from boards.models.thread import Thread
18 from boards.utils import datetime_to_epoch, cached_result
17 from boards.utils import datetime_to_epoch, cached_result
19
18
20
19
@@ -111,7 +110,6 b' class PostManager(models.Manager):'
111 post_image.id, post.id))
110 post_image.id, post.id))
112 post.images.add(post_image)
111 post.images.add(post_image)
113
112
114 thread.replies.add(post)
115 list(map(thread.add_tag, tags))
113 list(map(thread.add_tag, tags))
116
114
117 if new_thread:
115 if new_thread:
@@ -134,7 +132,7 b' class PostManager(models.Manager):'
134 for post in posts:
132 for post in posts:
135 post.delete()
133 post.delete()
136
134
137 def connect_replies(self, post):
135 def connect_replies(self, post):
138 """
136 """
139 Connects replies to a post to show them as a reflink map
137 Connects replies to a post to show them as a reflink map
140 """
138 """
@@ -295,7 +293,7 b' class Post(models.Model, Viewable):'
295
293
296 return link
294 return link
297
295
298 def get_thread(self) -> Thread:
296 def get_thread(self):
299 """
297 """
300 Gets post's thread.
298 Gets post's thread.
301 """
299 """
@@ -6,6 +6,7 b' from django.db import models'
6
6
7 from boards import settings
7 from boards import settings
8 from boards.utils import cached_result
8 from boards.utils import cached_result
9 from boards.models.post import Post
9
10
10
11
11 __author__ = 'neko259'
12 __author__ = 'neko259'
@@ -52,8 +53,6 b' class Thread(models.Model):'
52 tags = models.ManyToManyField('Tag')
53 tags = models.ManyToManyField('Tag')
53 bump_time = models.DateTimeField()
54 bump_time = models.DateTimeField()
54 last_edit_time = models.DateTimeField()
55 last_edit_time = models.DateTimeField()
55 replies = models.ManyToManyField('Post', symmetrical=False, null=True,
56 blank=True, related_name='tre+')
57 archived = models.BooleanField(default=False)
56 archived = models.BooleanField(default=False)
58 bumpable = models.BooleanField(default=True)
57 bumpable = models.BooleanField(default=True)
59
58
@@ -78,10 +77,10 b' class Thread(models.Model):'
78 logger.info('Bumped thread %d' % self.id)
77 logger.info('Bumped thread %d' % self.id)
79
78
80 def get_reply_count(self):
79 def get_reply_count(self):
81 return self.replies.count()
80 return self.get_replies().count()
82
81
83 def get_images_count(self):
82 def get_images_count(self):
84 return self.replies.annotate(images_count=Count(
83 return self.get_replies().annotate(images_count=Count(
85 'images')).aggregate(Sum('images_count'))['images_count__sum']
84 'images')).aggregate(Sum('images_count'))['images_count__sum']
86
85
87 def can_bump(self):
86 def can_bump(self):
@@ -121,7 +120,8 b' class Thread(models.Model):'
121 Gets sorted thread posts
120 Gets sorted thread posts
122 """
121 """
123
122
124 query = self.replies.order_by('pub_time').prefetch_related('images')
123 query = Post.objects.filter(thread_new=self)
124 query = query.order_by('pub_time').prefetch_related('images')
125 if view_fields_only:
125 if view_fields_only:
126 query = query.defer('poster_user_agent')
126 query = query.defer('poster_user_agent')
127 return query.all()
127 return query.all()
@@ -146,7 +146,7 b' class Thread(models.Model):'
146 Gets the first post of the thread
146 Gets the first post of the thread
147 """
147 """
148
148
149 query = self.replies.order_by('pub_time')
149 query = self.get_replies().order_by('pub_time')
150 if only_id:
150 if only_id:
151 query = query.only('id')
151 query = query.only('id')
152 opening_post = query.first()
152 opening_post = query.first()
General Comments 0
You need to be logged in to leave comments. Login now