diff options
author | Chocobozzz <me@florianbigard.com> | 2018-09-13 13:59:41 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-09-13 14:14:15 +0200 |
commit | 6f0c46be8c9f4690d5e5cb758c4df6164b006f83 (patch) | |
tree | 8c8b56cc2415a6da42e2630b24a4f638b441bdc5 | |
parent | c48e82b5e0478434de30626d14594a97f2402e7c (diff) | |
download | PeerTube-6f0c46be8c9f4690d5e5cb758c4df6164b006f83.tar.gz PeerTube-6f0c46be8c9f4690d5e5cb758c4df6164b006f83.tar.zst PeerTube-6f0c46be8c9f4690d5e5cb758c4df6164b006f83.zip |
Process last hour views instead of current hour
-rw-r--r-- | server/lib/job-queue/handlers/video-views.ts | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/server/lib/job-queue/handlers/video-views.ts b/server/lib/job-queue/handlers/video-views.ts index 8a011d109..cf180a11a 100644 --- a/server/lib/job-queue/handlers/video-views.ts +++ b/server/lib/job-queue/handlers/video-views.ts | |||
@@ -2,11 +2,17 @@ import { Redis } from '../../redis' | |||
2 | import { logger } from '../../../helpers/logger' | 2 | import { logger } from '../../../helpers/logger' |
3 | import { VideoModel } from '../../../models/video/video' | 3 | import { VideoModel } from '../../../models/video/video' |
4 | import { VideoViewModel } from '../../../models/video/video-views' | 4 | import { VideoViewModel } from '../../../models/video/video-views' |
5 | import { isTestInstance } from '../../../helpers/core-utils' | ||
5 | 6 | ||
6 | async function processVideosViewsViews () { | 7 | async function processVideosViewsViews () { |
7 | const hour = new Date().getHours() | 8 | const lastHour = new Date() |
8 | const startDate = new Date().setMinutes(0, 0, 0) | 9 | |
9 | const endDate = new Date().setMinutes(59, 59, 999) | 10 | // In test mode, we run this function multiple times per hour, so we don't want the values of the previous hour |
11 | if (!isTestInstance()) lastHour.setHours(lastHour.getHours() - 1) | ||
12 | |||
13 | const hour = lastHour.getHours() | ||
14 | const startDate = lastHour.setMinutes(0, 0, 0) | ||
15 | const endDate = lastHour.setMinutes(59, 59, 999) | ||
10 | 16 | ||
11 | const videoIds = await Redis.Instance.getVideosIdViewed(hour) | 17 | const videoIds = await Redis.Instance.getVideosIdViewed(hour) |
12 | if (videoIds.length === 0) return | 18 | if (videoIds.length === 0) return |