From 5fe9f2baee927a25d409dd1cb446b41d93345565 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 1 Feb 2019 10:00:36 +0900 Subject: [PATCH] Improve performance --- src/server/api/common/get-hide-users.ts | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/server/api/common/get-hide-users.ts b/src/server/api/common/get-hide-users.ts index b3ddcec1f..968b357ab 100644 --- a/src/server/api/common/get-hide-users.ts +++ b/src/server/api/common/get-hide-users.ts @@ -7,14 +7,19 @@ export async function getHideUserIds(me: IUser) { return me ? await getHideUserIdsById(me._id) : []; } -export async function getHideUserIdsById(meId: mongo.ObjectID) { - const suspended = (await User.find({ - isSuspended: true - })).map(user => user._id); +export async function getHideUserIdsById(meId?: mongo.ObjectID) { + const [suspended, muted] = await Promise.all([ + User.find({ + isSuspended: true + }, { + fields: { + _id: true + } + }), + meId ? Mute.find({ + muterId: meId + }) : Promise.resolve([]) + ]); - const muted = meId ? (await Mute.find({ - muterId: meId - })).map(mute => mute.muteeId) : []; - - return unique(suspended.concat(muted)); + return unique(suspended.map(user => user._id).concat(muted.map(mute => mute.muteeId))); }