From fb993c8a5596dcc1b711981b24177104e3595b04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Mon, 24 Mar 2025 16:01:08 -0400 Subject: [PATCH] refactor: use promise.all --- src/user/index.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) 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; };