##// END OF EJS Templates
Speed up tag list generation a bit
neko259 -
r606:01b85c7d default
parent child Browse files
Show More
@@ -41,9 +41,9 b' class Tag(models.Model):'
41 return self.name
41 return self.name
42
42
43 def is_empty(self):
43 def is_empty(self):
44 return self.get_post_count() == 0
44 return self.get_thread_count() == 0
45
45
46 def get_post_count(self):
46 def get_thread_count(self):
47 return self.threads.count()
47 return self.threads.count()
48
48
49 def get_popularity(self):
49 def get_popularity(self):
@@ -51,13 +51,9 b' class Tag(models.Model):'
51
51
52 tag_reply_count = 0.0
52 tag_reply_count = 0.0
53
53
54 for thread in self.threads.all():
54 tag_reply_count += self.get_post_count()
55 if thread.archived:
55 tag_reply_count +=\
56 modifier = ARCHIVE_POPULARITY_MODIFIER
56 self.get_post_count(archived=True) * ARCHIVE_POPULARITY_MODIFIER
57 else:
58 modifier = 1
59 tag_reply_count += thread.get_reply_count() * modifier \
60 / thread.tags.all().count()
61
57
62 popularity = tag_reply_count / all_post_count
58 popularity = tag_reply_count / all_post_count
63
59
@@ -92,3 +88,12 b' class Tag(models.Model):'
92 font_value = min(font_value, MAX_TAG_FONT)
88 font_value = min(font_value, MAX_TAG_FONT)
93
89
94 return str(font_value)
90 return str(font_value)
91
92 def get_post_count(self, archived=False):
93 posts_count = 0
94
95 for thread in self.threads.annotate(Count('replies')).filter(
96 archived=archived):
97 posts_count += thread.replies__count
98
99 return posts_count
General Comments 0
You need to be logged in to leave comments. Login now