From 5ab83ff9d8a6a43027e1327e7e2b80f26dd4c5f5 Mon Sep 17 00:00:00 2001 From: riku6460 <17585784+riku6460@users.noreply.github.com> Date: Sat, 13 Jul 2024 01:52:40 +0900 Subject: [PATCH] =?UTF-8?q?enhance(backend):=20=E3=81=84=E3=81=8F=E3=81=A4?= =?UTF-8?q?=E3=81=8B=E3=81=AE=E3=82=A8=E3=83=B3=E3=83=89=E3=83=9D=E3=82=A4?= =?UTF-8?q?=E3=83=B3=E3=83=88=E3=81=A7=E5=87=8D=E7=B5=90=E6=B8=88=E3=81=BF?= =?UTF-8?q?=E3=81=AE=E3=83=A6=E3=83=BC=E3=82=B6=E3=83=BC=E3=81=8C=E5=B1=85?= =?UTF-8?q?=E3=81=9F=E5=A0=B4=E5=90=88=E3=81=AE=E3=82=A8=E3=83=A9=E3=83=BC?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3=20(MisskeyIO#654)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/src/server/api/endpoints/roles/users.ts | 7 +++++-- .../api/endpoints/users/get-frequently-replied-users.ts | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/roles/users.ts b/packages/backend/src/server/api/endpoints/roles/users.ts index 85d100ce1..19386ae9d 100644 --- a/packages/backend/src/server/api/endpoints/roles/users.ts +++ b/packages/backend/src/server/api/endpoints/roles/users.ts @@ -11,6 +11,7 @@ import { QueryService } from '@/core/QueryService.js'; import { DI } from '@/di-symbols.js'; import { UserEntityService } from '@/core/entities/UserEntityService.js'; import { ApiError } from '../../error.js'; +import type { Packed } from '@/misc/json-schema.js'; export const meta = { tags: ['role', 'users'], @@ -92,10 +93,12 @@ export default class extends Endpoint { // eslint- .limit(ps.limit) .getMany(); - return await Promise.all(assigns.map(async assign => ({ + return (await Promise.allSettled(assigns.map(async assign => ({ id: assign.id, user: await this.userEntityService.pack(assign.user!, me, { schema: 'UserDetailed' }), - }))); + })))) + .filter((result): result is PromiseFulfilledResult<{ id: string; user: Packed<'UserDetailed'> }> => result.status === 'fulfilled') + .map(result => result.value); }); } } diff --git a/packages/backend/src/server/api/endpoints/users/get-frequently-replied-users.ts b/packages/backend/src/server/api/endpoints/users/get-frequently-replied-users.ts index 059e14a36..e5172226a 100644 --- a/packages/backend/src/server/api/endpoints/users/get-frequently-replied-users.ts +++ b/packages/backend/src/server/api/endpoints/users/get-frequently-replied-users.ts @@ -14,6 +14,7 @@ import { GetterService } from '@/server/api/GetterService.js'; import { CacheService } from '@/core/CacheService.js'; import { isUserRelated } from '@/misc/is-user-related.js'; import { ApiError } from '../../error.js'; +import { Packed } from '@/misc/json-schema.js'; export const meta = { tags: ['users'], @@ -131,10 +132,12 @@ export default class extends Endpoint { // eslint- const topRepliedUsers = repliedUsersSorted.slice(0, ps.limit); // Make replies object (includes weights) - const repliesObj = await Promise.all(topRepliedUsers.map(async (user) => ({ + const repliesObj = (await Promise.allSettled(topRepliedUsers.map(async (user) => ({ user: await this.userEntityService.pack(user, me, { schema: 'UserDetailed' }), weight: repliedUsers[user] / peak, - }))); + })))) + .filter((result): result is PromiseFulfilledResult<{ user: Packed<'UserDetailed'>; weight: number }> => result.status === 'fulfilled') + .map(result => result.value); return repliesObj; });