refactor: use promise.all

This commit is contained in:
Barış Soner Uşaklı
2025-03-24 16:01:08 -04:00
committed by Julian Lam
parent c1b7196429
commit 74661381d8

View File

@@ -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;
};