aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-06-17 14:17:06 +0200
committerChocobozzz <me@florianbigard.com>2022-06-17 14:17:06 +0200
commitfba911e2c89708a166636e3a93fcd8fcbc3de7e1 (patch)
tree8ad1e9c9abf3b021e343ed35618aa5d606fe03e5 /server/lib
parente69d1ed5cd4cc2b40914af98ffd8d54dff04cc9e (diff)
parentf27b7a750f1876632e84d594608d3d64ce974efc (diff)
downloadPeerTube-fba911e2c89708a166636e3a93fcd8fcbc3de7e1.tar.gz
PeerTube-fba911e2c89708a166636e3a93fcd8fcbc3de7e1.tar.zst
PeerTube-fba911e2c89708a166636e3a93fcd8fcbc3de7e1.zip
Merge branch 'release/4.2.0' into develop
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/activitypub/local-video-viewer.ts6
-rw-r--r--server/lib/activitypub/send/send-view.ts2
-rw-r--r--server/lib/activitypub/send/shared/audience-utils.ts6
-rw-r--r--server/lib/activitypub/send/shared/send-utils.ts23
-rw-r--r--server/lib/job-queue/job-queue.ts3
-rw-r--r--server/lib/views/shared/video-viewer-counters.ts1
6 files changed, 28 insertions, 13 deletions
diff --git a/server/lib/activitypub/local-video-viewer.ts b/server/lib/activitypub/local-video-viewer.ts
index 738083adc..bdd746791 100644
--- a/server/lib/activitypub/local-video-viewer.ts
+++ b/server/lib/activitypub/local-video-viewer.ts
@@ -23,7 +23,7 @@ async function createOrUpdateLocalVideoViewer (watchAction: WatchActionObject, v
23 : null, 23 : null,
24 24
25 videoId: video.id 25 videoId: video.id
26 }) 26 }, { transaction: t })
27 27
28 await LocalVideoViewerWatchSectionModel.bulkCreateSections({ 28 await LocalVideoViewerWatchSectionModel.bulkCreateSections({
29 localVideoViewerId: localVideoViewer.id, 29 localVideoViewerId: localVideoViewer.id,
@@ -31,7 +31,9 @@ async function createOrUpdateLocalVideoViewer (watchAction: WatchActionObject, v
31 watchSections: watchAction.watchSections.map(s => ({ 31 watchSections: watchAction.watchSections.map(s => ({
32 start: s.startTimestamp, 32 start: s.startTimestamp,
33 end: s.endTimestamp 33 end: s.endTimestamp
34 })) 34 })),
35
36 transaction: t
35 }) 37 })
36} 38}
37 39
diff --git a/server/lib/activitypub/send/send-view.ts b/server/lib/activitypub/send/send-view.ts
index 25a20ec6d..bf3451603 100644
--- a/server/lib/activitypub/send/send-view.ts
+++ b/server/lib/activitypub/send/send-view.ts
@@ -26,7 +26,7 @@ async function sendView (options: {
26 return buildViewActivity({ url, byActor, video, audience, type }) 26 return buildViewActivity({ url, byActor, video, audience, type })
27 } 27 }
28 28
29 return sendVideoRelatedActivity(activityBuilder, { byActor, video, transaction, contextType: 'View' }) 29 return sendVideoRelatedActivity(activityBuilder, { byActor, video, transaction, contextType: 'View', parallelizable: true })
30} 30}
31 31
32// --------------------------------------------------------------------------- 32// ---------------------------------------------------------------------------
diff --git a/server/lib/activitypub/send/shared/audience-utils.ts b/server/lib/activitypub/send/shared/audience-utils.ts
index ba4be487c..2f6b0741d 100644
--- a/server/lib/activitypub/send/shared/audience-utils.ts
+++ b/server/lib/activitypub/send/shared/audience-utils.ts
@@ -3,7 +3,7 @@ import { ACTIVITY_PUB } from '@server/initializers/constants'
3import { ActorModel } from '@server/models/actor/actor' 3import { ActorModel } from '@server/models/actor/actor'
4import { VideoModel } from '@server/models/video/video' 4import { VideoModel } from '@server/models/video/video'
5import { VideoShareModel } from '@server/models/video/video-share' 5import { VideoShareModel } from '@server/models/video/video-share'
6import { MActorFollowersUrl, MActorLight, MActorUrl, MCommentOwner, MCommentOwnerVideo, MVideoId } from '@server/types/models' 6import { MActorFollowersUrl, MActorUrl, MCommentOwner, MCommentOwnerVideo, MVideoId } from '@server/types/models'
7import { ActivityAudience } from '@shared/models' 7import { ActivityAudience } from '@shared/models'
8 8
9function getOriginVideoAudience (accountActor: MActorUrl, actorsInvolvedInVideo: MActorFollowersUrl[] = []): ActivityAudience { 9function getOriginVideoAudience (accountActor: MActorUrl, actorsInvolvedInVideo: MActorFollowersUrl[] = []): ActivityAudience {
@@ -51,13 +51,13 @@ function getAudienceFromFollowersOf (actorsInvolvedInObject: MActorFollowersUrl[
51} 51}
52 52
53async function getActorsInvolvedInVideo (video: MVideoId, t: Transaction) { 53async function getActorsInvolvedInVideo (video: MVideoId, t: Transaction) {
54 const actors: MActorLight[] = await VideoShareModel.loadActorsByShare(video.id, t) 54 const actors = await VideoShareModel.listActorIdsAndFollowerUrlsByShare(video.id, t)
55 55
56 const videoAll = video as VideoModel 56 const videoAll = video as VideoModel
57 57
58 const videoActor = videoAll.VideoChannel?.Account 58 const videoActor = videoAll.VideoChannel?.Account
59 ? videoAll.VideoChannel.Account.Actor 59 ? videoAll.VideoChannel.Account.Actor
60 : await ActorModel.loadFromAccountByVideoId(video.id, t) 60 : await ActorModel.loadAccountActorFollowerUrlByVideoId(video.id, t)
61 61
62 actors.push(videoActor) 62 actors.push(videoActor)
63 63
diff --git a/server/lib/activitypub/send/shared/send-utils.ts b/server/lib/activitypub/send/shared/send-utils.ts
index dbcde91ee..fcec63991 100644
--- a/server/lib/activitypub/send/shared/send-utils.ts
+++ b/server/lib/activitypub/send/shared/send-utils.ts
@@ -15,17 +15,18 @@ async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAud
15 byActor: MActorLight 15 byActor: MActorLight
16 video: MVideoImmutable | MVideoAccountLight 16 video: MVideoImmutable | MVideoAccountLight
17 contextType: ContextType 17 contextType: ContextType
18 parallelizable?: boolean
18 transaction?: Transaction 19 transaction?: Transaction
19}) { 20}) {
20 const { byActor, video, transaction, contextType } = options 21 const { byActor, video, transaction, contextType, parallelizable } = options
21
22 const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, transaction)
23 22
24 // Send to origin 23 // Send to origin
25 if (video.isOwned() === false) { 24 if (video.isOwned() === false) {
26 return sendVideoActivityToOrigin(activityBuilder, options) 25 return sendVideoActivityToOrigin(activityBuilder, options)
27 } 26 }
28 27
28 const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, transaction)
29
29 // Send to followers 30 // Send to followers
30 const audience = getAudienceFromFollowersOf(actorsInvolvedInVideo) 31 const audience = getAudienceFromFollowersOf(actorsInvolvedInVideo)
31 const activity = activityBuilder(audience) 32 const activity = activityBuilder(audience)
@@ -38,6 +39,7 @@ async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAud
38 toFollowersOf: actorsInvolvedInVideo, 39 toFollowersOf: actorsInvolvedInVideo,
39 transaction, 40 transaction,
40 actorsException, 41 actorsException,
42 parallelizable,
41 contextType 43 contextType
42 }) 44 })
43} 45}
@@ -130,9 +132,10 @@ async function broadcastToFollowers (options: {
130 transaction: Transaction 132 transaction: Transaction
131 contextType: ContextType 133 contextType: ContextType
132 134
135 parallelizable?: boolean
133 actorsException?: MActorWithInboxes[] 136 actorsException?: MActorWithInboxes[]
134}) { 137}) {
135 const { data, byActor, toFollowersOf, transaction, contextType, actorsException = [] } = options 138 const { data, byActor, toFollowersOf, transaction, contextType, actorsException = [], parallelizable } = options
136 139
137 const uris = await computeFollowerUris(toFollowersOf, actorsException, transaction) 140 const uris = await computeFollowerUris(toFollowersOf, actorsException, transaction)
138 141
@@ -141,6 +144,7 @@ async function broadcastToFollowers (options: {
141 uris, 144 uris,
142 data, 145 data,
143 byActor, 146 byActor,
147 parallelizable,
144 contextType 148 contextType
145 }) 149 })
146 }) 150 })
@@ -173,8 +177,9 @@ function broadcastTo (options: {
173 data: any 177 data: any
174 byActor: MActorId 178 byActor: MActorId
175 contextType: ContextType 179 contextType: ContextType
180 parallelizable?: boolean // default to false
176}) { 181}) {
177 const { uris, data, byActor, contextType } = options 182 const { uris, data, byActor, contextType, parallelizable } = options
178 183
179 if (uris.length === 0) return undefined 184 if (uris.length === 0) return undefined
180 185
@@ -200,7 +205,13 @@ function broadcastTo (options: {
200 contextType 205 contextType
201 } 206 }
202 207
203 JobQueue.Instance.createJob({ type: 'activitypub-http-broadcast', payload }) 208 JobQueue.Instance.createJob({
209 type: parallelizable
210 ? 'activitypub-http-broadcast-parallel'
211 : 'activitypub-http-broadcast',
212
213 payload
214 })
204 } 215 }
205 216
206 for (const unicastUri of unicastUris) { 217 for (const unicastUri of unicastUris) {
diff --git a/server/lib/job-queue/job-queue.ts b/server/lib/job-queue/job-queue.ts
index 61e41fb0f..ce24763f1 100644
--- a/server/lib/job-queue/job-queue.ts
+++ b/server/lib/job-queue/job-queue.ts
@@ -43,6 +43,7 @@ import { processVideosViewsStats } from './handlers/video-views-stats'
43 43
44type CreateJobArgument = 44type CreateJobArgument =
45 { type: 'activitypub-http-broadcast', payload: ActivitypubHttpBroadcastPayload } | 45 { type: 'activitypub-http-broadcast', payload: ActivitypubHttpBroadcastPayload } |
46 { type: 'activitypub-http-broadcast-parallel', payload: ActivitypubHttpBroadcastPayload } |
46 { type: 'activitypub-http-unicast', payload: ActivitypubHttpUnicastPayload } | 47 { type: 'activitypub-http-unicast', payload: ActivitypubHttpUnicastPayload } |
47 { type: 'activitypub-http-fetcher', payload: ActivitypubHttpFetcherPayload } | 48 { type: 'activitypub-http-fetcher', payload: ActivitypubHttpFetcherPayload } |
48 { type: 'activitypub-http-cleaner', payload: {} } | 49 { type: 'activitypub-http-cleaner', payload: {} } |
@@ -68,6 +69,7 @@ export type CreateJobOptions = {
68 69
69const handlers: { [id in JobType]: (job: Job) => Promise<any> } = { 70const handlers: { [id in JobType]: (job: Job) => Promise<any> } = {
70 'activitypub-http-broadcast': processActivityPubHttpBroadcast, 71 'activitypub-http-broadcast': processActivityPubHttpBroadcast,
72 'activitypub-http-broadcast-parallel': processActivityPubHttpBroadcast,
71 'activitypub-http-unicast': processActivityPubHttpUnicast, 73 'activitypub-http-unicast': processActivityPubHttpUnicast,
72 'activitypub-http-fetcher': processActivityPubHttpFetcher, 74 'activitypub-http-fetcher': processActivityPubHttpFetcher,
73 'activitypub-cleaner': processActivityPubCleaner, 75 'activitypub-cleaner': processActivityPubCleaner,
@@ -93,6 +95,7 @@ const errorHandlers: { [id in JobType]?: (job: Job, err: any) => Promise<any> }
93const jobTypes: JobType[] = [ 95const jobTypes: JobType[] = [
94 'activitypub-follow', 96 'activitypub-follow',
95 'activitypub-http-broadcast', 97 'activitypub-http-broadcast',
98 'activitypub-http-broadcast-parallel',
96 'activitypub-http-fetcher', 99 'activitypub-http-fetcher',
97 'activitypub-http-unicast', 100 'activitypub-http-unicast',
98 'activitypub-cleaner', 101 'activitypub-cleaner',
diff --git a/server/lib/views/shared/video-viewer-counters.ts b/server/lib/views/shared/video-viewer-counters.ts
index 941b62ed7..999ab7d8d 100644
--- a/server/lib/views/shared/video-viewer-counters.ts
+++ b/server/lib/views/shared/video-viewer-counters.ts
@@ -1,4 +1,3 @@
1
2import { isTestInstance } from '@server/helpers/core-utils' 1import { isTestInstance } from '@server/helpers/core-utils'
3import { logger, loggerTagsFactory } from '@server/helpers/logger' 2import { logger, loggerTagsFactory } from '@server/helpers/logger'
4import { VIEW_LIFETIME } from '@server/initializers/constants' 3import { VIEW_LIFETIME } from '@server/initializers/constants'