Improve performance

This commit is contained in:
syuilo 2019-02-01 10:00:36 +09:00
parent c7ebf6f990
commit 5fe9f2baee
No known key found for this signature in database
GPG Key ID: BDC4C49D06AB9D69
1 changed files with 14 additions and 9 deletions

View File

@ -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({
export async function getHideUserIdsById(meId?: mongo.ObjectID) {
const [suspended, muted] = await Promise.all([
User.find({
isSuspended: true
})).map(user => user._id);
const muted = meId ? (await Mute.find({
}, {
fields: {
_id: true
}
}),
meId ? Mute.find({
muterId: meId
})).map(mute => mute.muteeId) : [];
}) : Promise.resolve([])
]);
return unique(suspended.concat(muted));
return unique(suspended.map(user => user._id).concat(muted.map(mute => mute.muteeId)));
}