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') {