aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/activitypub/process/process-create.ts13
-rw-r--r--server/lib/job-queue/handlers/video-views.ts13
2 files changed, 20 insertions, 6 deletions
diff --git a/server/lib/activitypub/process/process-create.ts b/server/lib/activitypub/process/process-create.ts
index f7fb09fba..cd7ea01aa 100644
--- a/server/lib/activitypub/process/process-create.ts
+++ b/server/lib/activitypub/process/process-create.ts
@@ -87,10 +87,19 @@ async function processCreateDislike (byActor: ActorModel, activity: ActivityCrea
87async function processCreateView (byActor: ActorModel, activity: ActivityCreate) { 87async function processCreateView (byActor: ActorModel, activity: ActivityCreate) {
88 const view = activity.object as ViewObject 88 const view = activity.object as ViewObject
89 89
90 const video = await VideoModel.loadByUrl(view.object) 90 const options = {
91 if (!video || video.isOwned() === false) return 91 videoObject: view.object,
92 fetchType: 'only-video' as 'only-video'
93 }
94 const { video } = await getOrCreateVideoAndAccountAndChannel(options)
92 95
93 await Redis.Instance.addVideoView(video.id) 96 await Redis.Instance.addVideoView(video.id)
97
98 if (video.isOwned()) {
99 // Don't resend the activity to the sender
100 const exceptions = [ byActor ]
101 await forwardVideoRelatedActivity(activity, undefined, exceptions, video)
102 }
94} 103}
95 104
96async function processCacheFile (byActor: ActorModel, activity: ActivityCreate) { 105async function processCacheFile (byActor: ActorModel, activity: ActivityCreate) {
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 }