##// 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 14 from boards.mdx_neboard import bbcode_extended
15 15 from boards.models import PostImage
16 16 from boards.models.base import Viewable
17 from boards.models.thread import Thread
18 17 from boards.utils import datetime_to_epoch, cached_result
19 18
20 19
@@ -111,7 +110,6 b' class PostManager(models.Manager):'
111 110 post_image.id, post.id))
112 111 post.images.add(post_image)
113 112
114 thread.replies.add(post)
115 113 list(map(thread.add_tag, tags))
116 114
117 115 if new_thread:
@@ -134,7 +132,7 b' class PostManager(models.Manager):'
134 132 for post in posts:
135 133 post.delete()
136 134
137 def connect_replies(self, post):
135 def connect_replies(self, post):
138 136 """
139 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 294 return link
297 295
298 def get_thread(self) -> Thread:
296 def get_thread(self):
299 297 """
300 298 Gets post's thread.
301 299 """
@@ -6,6 +6,7 b' from django.db import models'
6 6
7 7 from boards import settings
8 8 from boards.utils import cached_result
9 from boards.models.post import Post
9 10
10 11
11 12 __author__ = 'neko259'
@@ -52,8 +53,6 b' class Thread(models.Model):'
52 53 tags = models.ManyToManyField('Tag')
53 54 bump_time = models.DateTimeField()
54 55 last_edit_time = models.DateTimeField()
55 replies = models.ManyToManyField('Post', symmetrical=False, null=True,
56 blank=True, related_name='tre+')
57 56 archived = models.BooleanField(default=False)
58 57 bumpable = models.BooleanField(default=True)
59 58
@@ -78,10 +77,10 b' class Thread(models.Model):'
78 77 logger.info('Bumped thread %d' % self.id)
79 78
80 79 def get_reply_count(self):
81 return self.replies.count()
80 return self.get_replies().count()
82 81
83 82 def get_images_count(self):
84 return self.replies.annotate(images_count=Count(
83 return self.get_replies().annotate(images_count=Count(
85 84 'images')).aggregate(Sum('images_count'))['images_count__sum']
86 85
87 86 def can_bump(self):
@@ -121,7 +120,8 b' class Thread(models.Model):'
121 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 125 if view_fields_only:
126 126 query = query.defer('poster_user_agent')
127 127 return query.all()
@@ -146,7 +146,7 b' class Thread(models.Model):'
146 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 150 if only_id:
151 151 query = query.only('id')
152 152 opening_post = query.first()
General Comments 0
You need to be logged in to leave comments. Login now