diff options
author | Chocobozzz <me@florianbigard.com> | 2018-01-18 14:59:27 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-01-18 15:42:20 +0100 |
commit | 54e740594bc2eacd8026b5d2d6cfdfc06416a65b (patch) | |
tree | 486ce489a59653c667728be8f54ab038d37e1a99 /server/controllers/activitypub | |
parent | f05a1c30c15d2ae35c11e241ca039a72eeb7d6ad (diff) | |
download | PeerTube-54e740594bc2eacd8026b5d2d6cfdfc06416a65b.tar.gz PeerTube-54e740594bc2eacd8026b5d2d6cfdfc06416a65b.tar.zst PeerTube-54e740594bc2eacd8026b5d2d6cfdfc06416a65b.zip |
Avoid too many requests and fetching outbox
Diffstat (limited to 'server/controllers/activitypub')
-rw-r--r-- | server/controllers/activitypub/outbox.ts | 19 |
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' | |||
4 | import { pageToStartAndCount } from '../../helpers/core-utils' | 4 | import { pageToStartAndCount } from '../../helpers/core-utils' |
5 | import { ACTIVITY_PUB } from '../../initializers/constants' | 5 | import { ACTIVITY_PUB } from '../../initializers/constants' |
6 | import { announceActivityData, createActivityData } from '../../lib/activitypub/send' | 6 | import { announceActivityData, createActivityData } from '../../lib/activitypub/send' |
7 | import { buildAudience } from '../../lib/activitypub/send/misc' | ||
7 | import { getAnnounceActivityPubUrl } from '../../lib/activitypub/url' | 8 | import { getAnnounceActivityPubUrl } from '../../lib/activitypub/url' |
8 | import { asyncMiddleware, localAccountValidator } from '../../middlewares' | 9 | import { asyncMiddleware, localAccountValidator } from '../../middlewares' |
9 | import { AccountModel } from '../../models/account/account' | 10 | import { AccountModel } from '../../models/account/account' |
11 | import { ActorModel } from '../../models/activitypub/actor' | ||
10 | import { VideoModel } from '../../models/video/video' | 12 | import { VideoModel } from '../../models/video/video' |
11 | 13 | ||
12 | const outboxRouter = express.Router() | 14 | const 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 | } |