Show More
@@ -43,26 +43,12 b" REGEX_REPLY = re.compile('>>(\\d+)')" | |||||
43 |
|
43 | |||
44 | class PostManager(models.Manager): |
|
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 |
|
||||
58 | def create_post(self, title, text, image=None, thread=None, |
|
46 | def create_post(self, title, text, image=None, thread=None, | |
59 | ip=NO_IP, tags=None, user=None): |
|
47 | ip=NO_IP, tags=None, user=None): | |
60 | """ |
|
48 | """ | |
61 | Create new post |
|
49 | Create new post | |
62 | """ |
|
50 | """ | |
63 |
|
51 | |||
64 | self.clear_ppd_cache_if_old() |
|
|||
65 |
|
||||
66 | posting_time = timezone.now() |
|
52 | posting_time = timezone.now() | |
67 | if not thread: |
|
53 | if not thread: | |
68 | thread = Thread.objects.create(bump_time=posting_time, |
|
54 | thread = Thread.objects.create(bump_time=posting_time, | |
@@ -196,12 +182,11 b' class PostManager(models.Manager):' | |||||
196 | Get average count of posts per day for the last 7 days |
|
182 | Get average count of posts per day for the last 7 days | |
197 | """ |
|
183 | """ | |
198 |
|
184 | |||
199 | ppd = cache.get(CACHE_KEY_PPD) |
|
185 | today = datetime.now().date() | |
|
186 | ppd = cache.get(CACHE_KEY_PPD + str(today)) | |||
200 | if ppd: |
|
187 | if ppd: | |
201 | return ppd |
|
188 | return ppd | |
202 |
|
189 | |||
203 | today = datetime.now().date() |
|
|||
204 |
|
||||
205 | posts_per_days = [] |
|
190 | posts_per_days = [] | |
206 | for i in POSTS_PER_DAY_RANGE: |
|
191 | for i in POSTS_PER_DAY_RANGE: | |
207 | day_end = today - timedelta(i + 1) |
|
192 | day_end = today - timedelta(i + 1) |
General Comments 0
You need to be logged in to leave comments.
Login now