Skip to content

Node.js based forum software built for the modern web

refactor: use promise.all

Barış Soner Uşaklı74661381d858
diff --git a/src/user/index.js b/src/user/index.js
index 2059621f6d..0347ccaad3 100644
--- a/src/user/index.js
+++ b/src/user/index.js
@@ -46,13 +46,11 @@ User.exists = async function (uids) {
const singular = !Array.isArray(uids);
uids = singular ? [uids] : uids;
- const local = await db.isSortedSetMembers('users:joindate', uids);
- const remote = await db.exists(uids.map(uid => `userRemote:${uid}`));
- const results = local.map((a, idx) => {
- const b = remote[idx];
- return a || b;
- });
-
+ const [localExists, remoteExists] = await Promise.all([
+ db.isSortedSetMembers('users:joindate', uids),
+ db.exists(uids.map(uid => `userRemote:${uid}`)),
+ ]);
+ const results = localExists.map((local, idx) => local || remoteExists[idx]);
return singular ? results.pop() : results;
};