mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-12-25 09:13:07 +02:00
Improve performance
This commit is contained in:
parent
c7ebf6f990
commit
5fe9f2baee
1 changed files with 14 additions and 9 deletions
|
@ -7,14 +7,19 @@ export async function getHideUserIds(me: IUser) {
|
||||||
return me ? await getHideUserIdsById(me._id) : [];
|
return me ? await getHideUserIdsById(me._id) : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getHideUserIdsById(meId: mongo.ObjectID) {
|
export async function getHideUserIdsById(meId?: mongo.ObjectID) {
|
||||||
const suspended = (await User.find({
|
const [suspended, muted] = await Promise.all([
|
||||||
|
User.find({
|
||||||
isSuspended: true
|
isSuspended: true
|
||||||
})).map(user => user._id);
|
}, {
|
||||||
|
fields: {
|
||||||
const muted = meId ? (await Mute.find({
|
_id: true
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
meId ? Mute.find({
|
||||||
muterId: meId
|
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)));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue