aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/job-queue/handlers
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/job-queue/handlers')
-rw-r--r--server/lib/job-queue/handlers/video-views.ts13
1 files changed, 9 insertions, 4 deletions
diff --git a/server/lib/job-queue/handlers/video-views.ts b/server/lib/job-queue/handlers/video-views.ts
index f44c3c727..038ef43e2 100644
--- a/server/lib/job-queue/handlers/video-views.ts
+++ b/server/lib/job-queue/handlers/video-views.ts
@@ -24,12 +24,10 @@ async function processVideosViews () {
24 try { 24 try {
25 const views = await Redis.Instance.getVideoViews(videoId, hour) 25 const views = await Redis.Instance.getVideoViews(videoId, hour)
26 if (isNaN(views)) { 26 if (isNaN(views)) {
27 logger.error('Cannot process videos views of video %d in hour %d: views number is NaN.', videoId, hour) 27 logger.error('Cannot process videos views of video %d in hour %d: views number is NaN (%s).', videoId, hour, views)
28 } else { 28 } else {
29 logger.debug('Adding %d views to video %d in hour %d.', views, videoId, hour) 29 logger.debug('Adding %d views to video %d in hour %d.', views, videoId, hour)
30 30
31 await VideoModel.incrementViews(videoId, views)
32
33 try { 31 try {
34 await VideoViewModel.create({ 32 await VideoViewModel.create({
35 startDate, 33 startDate,
@@ -39,7 +37,14 @@ async function processVideosViews () {
39 }) 37 })
40 38
41 const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoId) 39 const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoId)
42 if (video.isOwned()) await federateVideoIfNeeded(video, false) 40 if (video.isOwned()) {
41 // If this is a remote video, the origin instance will send us an update
42 await VideoModel.incrementViews(videoId, views)
43
44 // Send video update
45 video.views += views
46 await federateVideoIfNeeded(video, false)
47 }
43 } catch (err) { 48 } catch (err) {
44 logger.debug('Cannot create video views for video %d in hour %d. Maybe the video does not exist anymore?', videoId, hour) 49 logger.debug('Cannot create video views for video %d in hour %d. Maybe the video does not exist anymore?', videoId, hour)
45 } 50 }