aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-01-18 14:59:27 +0100
committerChocobozzz <me@florianbigard.com>2018-01-18 15:42:20 +0100
commit54e740594bc2eacd8026b5d2d6cfdfc06416a65b (patch)
tree486ce489a59653c667728be8f54ab038d37e1a99 /server/controllers
parentf05a1c30c15d2ae35c11e241ca039a72eeb7d6ad (diff)
downloadPeerTube-54e740594bc2eacd8026b5d2d6cfdfc06416a65b.tar.gz
PeerTube-54e740594bc2eacd8026b5d2d6cfdfc06416a65b.tar.zst
PeerTube-54e740594bc2eacd8026b5d2d6cfdfc06416a65b.zip
Avoid too many requests and fetching outbox
Diffstat (limited to 'server/controllers')
-rw-r--r--server/controllers/activitypub/outbox.ts19
1 files changed, 15 insertions, 4 deletions
diff --git a/server/controllers/activitypub/outbox.ts b/server/controllers/activitypub/outbox.ts
index 620f9ee83..ab12a7c4b 100644
--- a/server/controllers/activitypub/outbox.ts
+++ b/server/controllers/activitypub/outbox.ts
@@ -4,9 +4,11 @@ import { activityPubCollectionPagination } from '../../helpers/activitypub'
4import { pageToStartAndCount } from '../../helpers/core-utils' 4import { pageToStartAndCount } from '../../helpers/core-utils'
5import { ACTIVITY_PUB } from '../../initializers/constants' 5import { ACTIVITY_PUB } from '../../initializers/constants'
6import { announceActivityData, createActivityData } from '../../lib/activitypub/send' 6import { announceActivityData, createActivityData } from '../../lib/activitypub/send'
7import { buildAudience } from '../../lib/activitypub/send/misc'
7import { getAnnounceActivityPubUrl } from '../../lib/activitypub/url' 8import { getAnnounceActivityPubUrl } from '../../lib/activitypub/url'
8import { asyncMiddleware, localAccountValidator } from '../../middlewares' 9import { asyncMiddleware, localAccountValidator } from '../../middlewares'
9import { AccountModel } from '../../models/account/account' 10import { AccountModel } from '../../models/account/account'
11import { ActorModel } from '../../models/activitypub/actor'
10import { VideoModel } from '../../models/video/video' 12import { VideoModel } from '../../models/video/video'
11 13
12const outboxRouter = express.Router() 14const outboxRouter = express.Router()
@@ -34,20 +36,29 @@ async function outboxController (req: express.Request, res: express.Response, ne
34 const data = await VideoModel.listAllAndSharedByActorForOutbox(actor.id, start, count) 36 const data = await VideoModel.listAllAndSharedByActorForOutbox(actor.id, start, count)
35 const activities: Activity[] = [] 37 const activities: Activity[] = []
36 38
39 // Avoid too many SQL requests
40 const actors = data.data.map(v => v.VideoChannel.Account.Actor)
41 actors.push(actor)
42
43 const followersMatrix = await ActorModel.getActorsFollowerSharedInboxUrls(actors, undefined)
44
37 for (const video of data.data) { 45 for (const video of data.data) {
38 const videoObject = video.toActivityPubObject() 46 const videoObject = video.toActivityPubObject()
39 47
40 const videoChannel = video.VideoChannel 48 const byActor = video.VideoChannel.Account.Actor
49 const createActivityAudience = buildAudience(followersMatrix[byActor.id])
50
41 // This is a shared video 51 // This is a shared video
42 if (video.VideoShares !== undefined && video.VideoShares.length !== 0) { 52 if (video.VideoShares !== undefined && video.VideoShares.length !== 0) {
43 const createActivity = await createActivityData(video.url, videoChannel.Account.Actor, videoObject, undefined) 53 const createActivity = await createActivityData(video.url, byActor, videoObject, undefined, createActivityAudience)
44 54
55 const announceAudience = buildAudience(followersMatrix[actor.id])
45 const url = getAnnounceActivityPubUrl(video.url, actor) 56 const url = getAnnounceActivityPubUrl(video.url, actor)
46 const announceActivity = await announceActivityData(url, actor, createActivity, undefined) 57 const announceActivity = await announceActivityData(url, actor, createActivity, undefined, announceAudience)
47 58
48 activities.push(announceActivity) 59 activities.push(announceActivity)
49 } else { 60 } else {
50 const createActivity = await createActivityData(video.url, videoChannel.Account.Actor, videoObject, undefined) 61 const createActivity = await createActivityData(video.url, byActor, videoObject, undefined, createActivityAudience)
51 62
52 activities.push(createActivity) 63 activities.push(createActivity)
53 } 64 }