From 5e89dfad557805b2d16a105af6d014517204a15e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Thu, 29 Feb 2024 16:59:40 -0500 Subject: [PATCH] refactor: move tomap inside --- src/database/mongo/hash.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/database/mongo/hash.js b/src/database/mongo/hash.js index c6616a3049..b428d9926b 100644 --- a/src/database/mongo/hash.js +++ b/src/database/mongo/hash.js @@ -125,20 +125,20 @@ module.exports = function (module) { } const cachedData = {}; const unCachedKeys = cache.getUnCachedKeys(keys, cachedData); - let data = []; + if (unCachedKeys.length >= 1) { - data = await module.client.collection('objects').find( + let data = await module.client.collection('objects').find( { _key: unCachedKeys.length === 1 ? unCachedKeys[0] : { $in: unCachedKeys } }, { projection: { _id: 0 } } ).toArray(); data = data.map(helpers.deserializeData); - } - const map = helpers.toMap(data); - unCachedKeys.forEach((key) => { - cachedData[key] = map[key] || null; - cache.set(key, cachedData[key]); - }); + const map = helpers.toMap(data); + unCachedKeys.forEach((key) => { + cachedData[key] = map[key] || null; + cache.set(key, cachedData[key]); + }); + } if (!Array.isArray(fields) || !fields.length) { return keys.map(key => (cachedData[key] ? { ...cachedData[key] } : null));