aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-04-18 16:04:49 +0200
committerChocobozzz <me@florianbigard.com>2018-04-18 16:04:49 +0200
commitf55e5a7bf81c2c27db1514273e3366511aabf4ae (patch)
tree7374d57557b770fbbea8b9410ec6f2e133a086c0 /server/lib
parent5350fd8e5b2b2d017b16d97828893a8a4a40bd89 (diff)
downloadPeerTube-f55e5a7bf81c2c27db1514273e3366511aabf4ae.tar.gz
PeerTube-f55e5a7bf81c2c27db1514273e3366511aabf4ae.tar.zst
PeerTube-f55e5a7bf81c2c27db1514273e3366511aabf4ae.zip
Process broadcast requests in parallel
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/job-queue/handlers/activitypub-http-broadcast.ts17
1 files changed, 7 insertions, 10 deletions
diff --git a/server/lib/job-queue/handlers/activitypub-http-broadcast.ts b/server/lib/job-queue/handlers/activitypub-http-broadcast.ts
index 78878fc01..38b8393f4 100644
--- a/server/lib/job-queue/handlers/activitypub-http-broadcast.ts
+++ b/server/lib/job-queue/handlers/activitypub-http-broadcast.ts
@@ -1,8 +1,10 @@
1import * as kue from 'kue' 1import * as kue from 'kue'
2import * as Bluebird from 'bluebird'
2import { logger } from '../../../helpers/logger' 3import { logger } from '../../../helpers/logger'
3import { doRequest } from '../../../helpers/requests' 4import { doRequest } from '../../../helpers/requests'
4import { ActorFollowModel } from '../../../models/activitypub/actor-follow' 5import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
5import { buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils' 6import { buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils'
7import { BROADCAST_CONCURRENCY } from '../../../initializers'
6 8
7export type ActivitypubHttpBroadcastPayload = { 9export type ActivitypubHttpBroadcastPayload = {
8 uris: string[] 10 uris: string[]
@@ -28,16 +30,11 @@ async function processActivityPubHttpBroadcast (job: kue.Job) {
28 const badUrls: string[] = [] 30 const badUrls: string[] = []
29 const goodUrls: string[] = [] 31 const goodUrls: string[] = []
30 32
31 for (const uri of payload.uris) { 33 await Bluebird.map(payload.uris, uri => {
32 options.uri = uri 34 return doRequest(Object.assign({}, options, { uri }))
33 35 .then(() => goodUrls.push(uri))
34 try { 36 .catch(() => badUrls.push(uri))
35 await doRequest(options) 37 }, { concurrency: BROADCAST_CONCURRENCY })
36 goodUrls.push(uri)
37 } catch (err) {
38 badUrls.push(uri)
39 }
40 }
41 38
42 return ActorFollowModel.updateActorFollowsScore(goodUrls, badUrls, undefined) 39 return ActorFollowModel.updateActorFollowsScore(goodUrls, badUrls, undefined)
43} 40}