diff options
| author | tamaina <tamaina@hotmail.co.jp> | 2023-07-05 12:15:48 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-05 12:15:48 +0900 |
| commit | 22227fa641f80240ab5f134007067d1b1048095a (patch) | |
| tree | 31e3cb94c364d4c6172f895a8764f4ae310c4056 /packages/backend/src/core/QueueService.ts | |
| parent | enhance(frontend): Better Timeline(MkPagination) Experience (#11066) (diff) | |
| download | sharkey-22227fa641f80240ab5f134007067d1b1048095a.tar.gz sharkey-22227fa641f80240ab5f134007067d1b1048095a.tar.bz2 sharkey-22227fa641f80240ab5f134007067d1b1048095a.zip | |
perf(backend): Use addBulk to add deliver queues (#11114)
Diffstat (limited to 'packages/backend/src/core/QueueService.ts')
| -rw-r--r-- | packages/backend/src/core/QueueService.ts | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/packages/backend/src/core/QueueService.ts b/packages/backend/src/core/QueueService.ts index 5b7359074e..48ff00c8ce 100644 --- a/packages/backend/src/core/QueueService.ts +++ b/packages/backend/src/core/QueueService.ts @@ -8,7 +8,7 @@ import { DI } from '@/di-symbols.js'; import { bindThis } from '@/decorators.js'; import type { Antenna } from '@/server/api/endpoints/i/import-antennas.js'; import type { DbQueue, DeliverQueue, EndedPollNotificationQueue, InboxQueue, ObjectStorageQueue, RelationshipQueue, SystemQueue, WebhookDeliverQueue } from './QueueModule.js'; -import type { DbJobData, RelationshipJobData, ThinUser } from '../queue/types.js'; +import type { DbJobData, DeliverJobData, RelationshipJobData, ThinUser } from '../queue/types.js'; import type httpSignature from '@peertube/http-signature'; import type * as Bull from 'bullmq'; @@ -69,7 +69,7 @@ export class QueueService { if (content == null) return null; if (to == null) return null; - const data = { + const data: DeliverJobData = { user: { id: user.id, }, @@ -88,6 +88,38 @@ export class QueueService { }); } + /** + * ApDeliverManager-DeliverManager.execute()からinboxesを突っ込んでaddBulkしたい + * @param user `{ id: string; }` この関数ではThinUserに変換しないので前もって変換してください + * @param content IActivity | null + * @param inboxes `Map<string, boolean>` / key: to (inbox url), value: isSharedInbox (whether it is sharedInbox) + * @returns void + */ + @bindThis + public async deliverMany(user: ThinUser, content: IActivity | null, inboxes: Map<string, boolean>) { + const opts = { + attempts: this.config.deliverJobMaxAttempts ?? 12, + backoff: { + type: 'custom', + }, + removeOnComplete: true, + removeOnFail: true, + }; + + await this.deliverQueue.addBulk(Array.from(inboxes.entries()).map(d => ({ + name: d[0], + data: { + user, + content, + to: d[0], + isSharedInbox: d[1], + } as DeliverJobData, + opts, + }))); + + return; + } + @bindThis public inbox(activity: IActivity, signature: httpSignature.IParsedSignature) { const data = { |