##// END OF EJS Templates
Count PPD only once per day if cache exists.
neko259 -
r417:dc7b6275 default
parent child Browse files
Show More
@@ -43,9 +43,21 b" REGEX_REPLY = re.compile('>>(\\d+)')"
43 43
44 44 class PostManager(models.Manager):
45 45
46 def clear_ppd_cache_if_old(self):
47 """
48 If new post in the other day then current post, a day has changed
49 and we need to remove the PPD cache and recalculate PPD including the
50 previous day
51 """
52
53 today = datetime.now().date()
54 posts = self.filter(pub_time__gte=today)
55 if posts.exists():
56 cache.delete(CACHE_KEY_PPD)
57
46 58 def create_post(self, title, text, image=None, thread=None,
47 59 ip=NO_IP, tags=None, user=None):
48 cache.delete(CACHE_KEY_PPD)
60 self.clear_ppd_cache_if_old()
49 61
50 62 posting_time = timezone.now()
51 63 if not thread:
@@ -62,7 +74,7 b' class PostManager(models.Manager):'
62 74 thread_new=thread,
63 75 image=image,
64 76 poster_ip=ip,
65 poster_user_agent=UNKNOWN_UA,
77 poster_user_agent=UNKNOWN_UA, # TODO Get UA at last!
66 78 last_edit_time=posting_time,
67 79 user=user)
68 80
@@ -162,7 +174,7 b' class PostManager(models.Manager):'
162 174 return int(math.ceil(thread_count / float(settings.THREADS_PER_PAGE)))
163 175
164 176 def get_posts_per_day(self):
165 """Get count of posts for the current day"""
177 """Get average count of posts per day for the last 7 days"""
166 178
167 179 ppd = cache.get(CACHE_KEY_PPD)
168 180 if ppd:
General Comments 0
You need to be logged in to leave comments. Login now