diff options
author | Chocobozzz <me@florianbigard.com> | 2018-11-15 16:18:12 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-11-15 16:38:37 +0100 |
commit | 030177d246834fdba89be9bbaeac497589b47102 (patch) | |
tree | a0c5b2e59aeb01322cff9042ceb31d49aadda908 /server/lib | |
parent | 650e3d5ce380026cc79bcd271915cf7e6f51c24c (diff) | |
download | PeerTube-030177d246834fdba89be9bbaeac497589b47102.tar.gz PeerTube-030177d246834fdba89be9bbaeac497589b47102.tar.zst PeerTube-030177d246834fdba89be9bbaeac497589b47102.zip |
Don't forward view, send updates instead
To avoid inconsistencies in the federation, now the origin server will
tell other instances what is the correct number of views
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/activitypub/process/process-create.ts | 16 | ||||
-rw-r--r-- | server/lib/job-queue/handlers/video-views.ts | 8 | ||||
-rw-r--r-- | server/lib/job-queue/job-queue.ts | 4 |
3 files changed, 12 insertions, 16 deletions
diff --git a/server/lib/activitypub/process/process-create.ts b/server/lib/activitypub/process/process-create.ts index 920d02cd2..214e14546 100644 --- a/server/lib/activitypub/process/process-create.ts +++ b/server/lib/activitypub/process/process-create.ts | |||
@@ -13,7 +13,8 @@ import { forwardVideoRelatedActivity } from '../send/utils' | |||
13 | import { Redis } from '../../redis' | 13 | import { Redis } from '../../redis' |
14 | import { createOrUpdateCacheFile } from '../cache-file' | 14 | import { createOrUpdateCacheFile } from '../cache-file' |
15 | import { immutableAssign } from '../../../tests/utils' | 15 | import { immutableAssign } from '../../../tests/utils' |
16 | import { getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url' | 16 | import { getVideoDislikeActivityPubUrl } from '../url' |
17 | import { VideoModel } from '../../../models/video/video' | ||
17 | 18 | ||
18 | async function processCreateActivity (activity: ActivityCreate, byActor: ActorModel) { | 19 | async function processCreateActivity (activity: ActivityCreate, byActor: ActorModel) { |
19 | const activityObject = activity.object | 20 | const activityObject = activity.object |
@@ -87,19 +88,10 @@ async function processCreateDislike (byActor: ActorModel, activity: ActivityCrea | |||
87 | async function processCreateView (byActor: ActorModel, activity: ActivityCreate) { | 88 | async function processCreateView (byActor: ActorModel, activity: ActivityCreate) { |
88 | const view = activity.object as ViewObject | 89 | const view = activity.object as ViewObject |
89 | 90 | ||
90 | const options = { | 91 | const video = await VideoModel.loadByUrl(view.object) |
91 | videoObject: view.object, | 92 | if (!video || video.isOwned() === false) return |
92 | fetchType: 'only-video' as 'only-video' | ||
93 | } | ||
94 | const { video } = await getOrCreateVideoAndAccountAndChannel(options) | ||
95 | 93 | ||
96 | await Redis.Instance.addVideoView(video.id) | 94 | 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 | } | ||
103 | } | 95 | } |
104 | 96 | ||
105 | async function processCacheFile (byActor: ActorModel, activity: ActivityCreate) { | 97 | async 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 cf180a11a..2ceec2342 100644 --- a/server/lib/job-queue/handlers/video-views.ts +++ b/server/lib/job-queue/handlers/video-views.ts | |||
@@ -3,8 +3,9 @@ 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 | import { isTestInstance } from '../../../helpers/core-utils' |
6 | import { federateVideoIfNeeded } from '../../activitypub' | ||
6 | 7 | ||
7 | async function processVideosViewsViews () { | 8 | async function processVideosViews () { |
8 | const lastHour = new Date() | 9 | const lastHour = new Date() |
9 | 10 | ||
10 | // In test mode, we run this function multiple times per hour, so we don't want the values of the previous hour | 11 | // In test mode, we run this function multiple times per hour, so we don't want the values of the previous hour |
@@ -36,6 +37,9 @@ async function processVideosViewsViews () { | |||
36 | views, | 37 | views, |
37 | videoId | 38 | videoId |
38 | }) | 39 | }) |
40 | |||
41 | const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoId) | ||
42 | await federateVideoIfNeeded(video, false) | ||
39 | } catch (err) { | 43 | } catch (err) { |
40 | logger.debug('Cannot create video views for video %d in hour %d. Maybe the video does not exist anymore?', videoId, hour) | 44 | logger.debug('Cannot create video views for video %d in hour %d. Maybe the video does not exist anymore?', videoId, hour) |
41 | } | 45 | } |
@@ -51,5 +55,5 @@ async function processVideosViewsViews () { | |||
51 | // --------------------------------------------------------------------------- | 55 | // --------------------------------------------------------------------------- |
52 | 56 | ||
53 | export { | 57 | export { |
54 | processVideosViewsViews | 58 | processVideosViews |
55 | } | 59 | } |
diff --git a/server/lib/job-queue/job-queue.ts b/server/lib/job-queue/job-queue.ts index 0696ba43c..4cfd4d253 100644 --- a/server/lib/job-queue/job-queue.ts +++ b/server/lib/job-queue/job-queue.ts | |||
@@ -10,7 +10,7 @@ import { EmailPayload, processEmail } from './handlers/email' | |||
10 | import { processVideoFile, processVideoFileImport, VideoFileImportPayload, VideoFilePayload } from './handlers/video-file' | 10 | import { processVideoFile, processVideoFileImport, VideoFileImportPayload, VideoFilePayload } from './handlers/video-file' |
11 | import { ActivitypubFollowPayload, processActivityPubFollow } from './handlers/activitypub-follow' | 11 | import { ActivitypubFollowPayload, processActivityPubFollow } from './handlers/activitypub-follow' |
12 | import { processVideoImport, VideoImportPayload } from './handlers/video-import' | 12 | import { processVideoImport, VideoImportPayload } from './handlers/video-import' |
13 | import { processVideosViewsViews } from './handlers/video-views' | 13 | import { processVideosViews } from './handlers/video-views' |
14 | 14 | ||
15 | type CreateJobArgument = | 15 | type CreateJobArgument = |
16 | { type: 'activitypub-http-broadcast', payload: ActivitypubHttpBroadcastPayload } | | 16 | { type: 'activitypub-http-broadcast', payload: ActivitypubHttpBroadcastPayload } | |
@@ -32,7 +32,7 @@ const handlers: { [ id in JobType ]: (job: Bull.Job) => Promise<any>} = { | |||
32 | 'video-file': processVideoFile, | 32 | 'video-file': processVideoFile, |
33 | 'email': processEmail, | 33 | 'email': processEmail, |
34 | 'video-import': processVideoImport, | 34 | 'video-import': processVideoImport, |
35 | 'videos-views': processVideosViewsViews | 35 | 'videos-views': processVideosViews |
36 | } | 36 | } |
37 | 37 | ||
38 | const jobTypes: JobType[] = [ | 38 | const jobTypes: JobType[] = [ |