From 545ab8036316f7b00becf239dbced88068ebcc50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=BE=E3=81=A3=E3=81=A1=E3=82=83=E3=81=A8=E3=83=BC?= =?UTF-8?q?=E3=81=AB=E3=82=85?= <17376330+u1-liquid@users.noreply.github.com> Date: Sun, 3 Sep 2023 23:20:18 +0900 Subject: [PATCH] =?UTF-8?q?=E5=87=8D=E7=B5=90=E3=81=95=E3=82=8C=E3=81=9F?= =?UTF-8?q?=E3=83=A6=E3=83=BC=E3=82=B6=E3=83=BC=E3=81=8C=E5=90=AB=E3=81=BE?= =?UTF-8?q?=E3=82=8C=E3=81=A6=E3=81=84=E3=82=8B=E5=A0=B4=E5=90=88=E4=B8=80?= =?UTF-8?q?=E9=83=A8=E3=81=AE=E6=A9=9F=E8=83=BD=E3=81=8C=E8=AA=A4=E5=8B=95?= =?UTF-8?q?=E4=BD=9C=E3=81=99=E3=82=8B=E4=B8=8D=E5=85=B7=E5=90=88=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3=20(MisskeyIO#161)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit z-6561 --- .../src/core/entities/NoteReactionEntityService.ts | 13 +++++++++++++ .../src/server/api/endpoints/drive/files/find.ts | 2 +- .../src/server/api/endpoints/notes/reactions.ts | 2 +- .../src/server/api/endpoints/users/reactions.ts | 2 +- .../backend/src/server/api/endpoints/users/show.ts | 7 ++++--- 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/packages/backend/src/core/entities/NoteReactionEntityService.ts b/packages/backend/src/core/entities/NoteReactionEntityService.ts index e3574e681a..838910df3b 100644 --- a/packages/backend/src/core/entities/NoteReactionEntityService.ts +++ b/packages/backend/src/core/entities/NoteReactionEntityService.ts @@ -64,4 +64,17 @@ export class NoteReactionEntityService implements OnModuleInit { } : {}), }; } + + @bindThis + public async packMany( + reactions: (MiNoteReaction['id'] | MiNoteReaction)[], + me: { id: MiUser['id'] } | null | undefined, + options?: { + withNote: boolean; + }, + ) : Promise[]> { + return (await Promise.allSettled(reactions.map(x => this.pack(x, me, options)))) + .filter(result => result.status === 'fulfilled') + .map(result => (result as PromiseFulfilledResult>).value); + } } diff --git a/packages/backend/src/server/api/endpoints/drive/files/find.ts b/packages/backend/src/server/api/endpoints/drive/files/find.ts index da503fdb17..f14eb23847 100644 --- a/packages/backend/src/server/api/endpoints/drive/files/find.ts +++ b/packages/backend/src/server/api/endpoints/drive/files/find.ts @@ -55,7 +55,7 @@ export default class extends Endpoint { folderId: ps.folderId ?? IsNull(), }); - return await Promise.all(files.map(file => this.driveFileEntityService.pack(file, me, { self: true }))); + return await this.driveFileEntityService.packMany(files, me, { self: true }); }); } } diff --git a/packages/backend/src/server/api/endpoints/notes/reactions.ts b/packages/backend/src/server/api/endpoints/notes/reactions.ts index 8f5e7d024b..1304fe638e 100644 --- a/packages/backend/src/server/api/endpoints/notes/reactions.ts +++ b/packages/backend/src/server/api/endpoints/notes/reactions.ts @@ -83,7 +83,7 @@ export default class extends Endpoint { relations: ['user', 'note'], }); - return await Promise.all(reactions.map(reaction => this.noteReactionEntityService.pack(reaction, me))); + return await this.noteReactionEntityService.packMany(reactions, me); }); } } diff --git a/packages/backend/src/server/api/endpoints/users/reactions.ts b/packages/backend/src/server/api/endpoints/users/reactions.ts index d65cdcfdb9..0dd19c2276 100644 --- a/packages/backend/src/server/api/endpoints/users/reactions.ts +++ b/packages/backend/src/server/api/endpoints/users/reactions.ts @@ -81,7 +81,7 @@ export default class extends Endpoint { .limit(ps.limit) .getMany(); - return await Promise.all(reactions.map(reaction => this.noteReactionEntityService.pack(reaction, me, { withNote: true }))); + return await this.noteReactionEntityService.packMany(reactions, me, { withNote: true }); }); } } diff --git a/packages/backend/src/server/api/endpoints/users/show.ts b/packages/backend/src/server/api/endpoints/users/show.ts index fb8a5c5941..75f99b16a4 100644 --- a/packages/backend/src/server/api/endpoints/users/show.ts +++ b/packages/backend/src/server/api/endpoints/users/show.ts @@ -113,12 +113,13 @@ export default class extends Endpoint { // リクエストされた通りに並べ替え const _users: MiUser[] = []; for (const id of ps.userIds) { - _users.push(users.find(x => x.id === id)!); + const user = users.find((u) => u.id === id); + if (user) _users.push(user); } - return await Promise.all(_users.map(u => this.userEntityService.pack(u, me, { + return await this.userEntityService.packMany(_users, me, { detail: true, - }))); + }); } else { // Lookup user if (typeof ps.host === 'string' && typeof ps.username === 'string') {