mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
refactor: move tomap inside
This commit is contained in:
@@ -125,20 +125,20 @@ module.exports = function (module) {
|
|||||||
}
|
}
|
||||||
const cachedData = {};
|
const cachedData = {};
|
||||||
const unCachedKeys = cache.getUnCachedKeys(keys, cachedData);
|
const unCachedKeys = cache.getUnCachedKeys(keys, cachedData);
|
||||||
let data = [];
|
|
||||||
if (unCachedKeys.length >= 1) {
|
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 } },
|
{ _key: unCachedKeys.length === 1 ? unCachedKeys[0] : { $in: unCachedKeys } },
|
||||||
{ projection: { _id: 0 } }
|
{ projection: { _id: 0 } }
|
||||||
).toArray();
|
).toArray();
|
||||||
data = data.map(helpers.deserializeData);
|
data = data.map(helpers.deserializeData);
|
||||||
}
|
|
||||||
|
|
||||||
const map = helpers.toMap(data);
|
const map = helpers.toMap(data);
|
||||||
unCachedKeys.forEach((key) => {
|
unCachedKeys.forEach((key) => {
|
||||||
cachedData[key] = map[key] || null;
|
cachedData[key] = map[key] || null;
|
||||||
cache.set(key, cachedData[key]);
|
cache.set(key, cachedData[key]);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (!Array.isArray(fields) || !fields.length) {
|
if (!Array.isArray(fields) || !fields.length) {
|
||||||
return keys.map(key => (cachedData[key] ? { ...cachedData[key] } : null));
|
return keys.map(key => (cachedData[key] ? { ...cachedData[key] } : null));
|
||||||
|
|||||||
Reference in New Issue
Block a user