diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2023-04-12 10:07:14 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2023-04-12 10:07:14 +0900 |
| commit | 77f91d67b42ae50ba6176ac95247aad80db34811 (patch) | |
| tree | 4f0eb4a41bf1b4673549eb9195872fb7c3aadb97 /packages/backend/src/core/AntennaService.ts | |
| parent | feat: queueing bulk follow/unfollow and block/unblock (#10544) (diff) | |
| download | sharkey-77f91d67b42ae50ba6176ac95247aad80db34811.tar.gz sharkey-77f91d67b42ae50ba6176ac95247aad80db34811.tar.bz2 sharkey-77f91d67b42ae50ba6176ac95247aad80db34811.zip | |
perf(backend): ノート作成時のアンテナ追加パフォーマンスを改善
Diffstat (limited to 'packages/backend/src/core/AntennaService.ts')
| -rw-r--r-- | packages/backend/src/core/AntennaService.ts | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/packages/backend/src/core/AntennaService.ts b/packages/backend/src/core/AntennaService.ts index 02e0b455fd..166c78f479 100644 --- a/packages/backend/src/core/AntennaService.ts +++ b/packages/backend/src/core/AntennaService.ts @@ -91,14 +91,24 @@ export class AntennaService implements OnApplicationShutdown { } @bindThis - public async addNoteToAntenna(antenna: Antenna, note: Note, noteUser: { id: User['id']; }): Promise<void> { - this.redisClient.xadd( - `antennaTimeline:${antenna.id}`, - 'MAXLEN', '~', '200', - '*', - 'note', note.id); - - this.globalEventService.publishAntennaStream(antenna.id, 'note', note); + public async addNoteToAntennas(note: Note, noteUser: { id: User['id']; username: string; host: string | null; }): Promise<void> { + const antennas = await this.getAntennas(); + const antennasWithMatchResult = await Promise.all(antennas.map(antenna => this.checkHitAntenna(antenna, note, noteUser).then(hit => [antenna, hit] as const))); + const matchedAntennas = antennasWithMatchResult.filter(([, hit]) => hit).map(([antenna]) => antenna); + + const redisPipeline = this.redisClient.pipeline(); + + for (const antenna of matchedAntennas) { + redisPipeline.xadd( + `antennaTimeline:${antenna.id}`, + 'MAXLEN', '~', '200', + '*', + 'note', note.id); + + this.globalEventService.publishAntennaStream(antenna.id, 'note', note); + } + + redisPipeline.exec(); } // NOTE: フォローしているユーザーのノート、リストのユーザーのノート、グループのユーザーのノート指定はパフォーマンス上の理由で無効になっている |