aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/job-queue/handlers/video-views.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-09-13 10:13:25 +0200
committerChocobozzz <me@florianbigard.com>2018-09-13 10:13:25 +0200
commit9431cabf8a92f602cf3b4626e12f23b0910f52a8 (patch)
treecef7f65ab8ea35c5974126a0e107eb140067070d /server/lib/job-queue/handlers/video-views.ts
parent662fb3ab5e3aafa49c96809a61239c9046a5c485 (diff)
downloadPeerTube-9431cabf8a92f602cf3b4626e12f23b0910f52a8.tar.gz
PeerTube-9431cabf8a92f602cf3b4626e12f23b0910f52a8.tar.zst
PeerTube-9431cabf8a92f602cf3b4626e12f23b0910f52a8.zip
Fix video views increment
Diffstat (limited to 'server/lib/job-queue/handlers/video-views.ts')
-rw-r--r--server/lib/job-queue/handlers/video-views.ts39
1 files changed, 24 insertions, 15 deletions
diff --git a/server/lib/job-queue/handlers/video-views.ts b/server/lib/job-queue/handlers/video-views.ts
index 875d8ab88..8a011d109 100644
--- a/server/lib/job-queue/handlers/video-views.ts
+++ b/server/lib/job-queue/handlers/video-views.ts
@@ -14,22 +14,31 @@ async function processVideosViewsViews () {
14 logger.info('Processing videos views in job for hour %d.', hour) 14 logger.info('Processing videos views in job for hour %d.', hour)
15 15
16 for (const videoId of videoIds) { 16 for (const videoId of videoIds) {
17 const views = await Redis.Instance.getVideoViews(videoId, hour) 17 try {
18 if (isNaN(views)) { 18 const views = await Redis.Instance.getVideoViews(videoId, hour)
19 logger.error('Cannot process videos views of video %s in hour %d: views number is NaN.', videoId, hour) 19 if (isNaN(views)) {
20 } else { 20 logger.error('Cannot process videos views of video %d in hour %d: views number is NaN.', videoId, hour)
21 logger.debug('Adding %d views to video %d in hour %d.', views, videoId, hour) 21 } else {
22 22 logger.debug('Adding %d views to video %d in hour %d.', views, videoId, hour)
23 await VideoModel.incrementViews(videoId, views) 23
24 await VideoViewModel.create({ 24 await VideoModel.incrementViews(videoId, views)
25 startDate, 25
26 endDate, 26 try {
27 views, 27 await VideoViewModel.create({
28 videoId 28 startDate,
29 }) 29 endDate,
30 views,
31 videoId
32 })
33 } catch (err) {
34 logger.debug('Cannot create video views for video %d in hour %d. Maybe the video does not exist anymore?', videoId, hour)
35 }
36 }
37
38 await Redis.Instance.deleteVideoViews(videoId, hour)
39 } catch (err) {
40 logger.error('Cannot update video views of video %d in hour %d.', videoId, hour)
30 } 41 }
31
32 await Redis.Instance.deleteVideoViews(videoId, hour)
33 } 42 }
34} 43}
35 44