refactor: shorter map

v1.18.x
Barış Soner Uşaklı 5 years ago
parent 039710493a
commit 572bc29742

@ -82,8 +82,8 @@ module.exports = function (module) {
} }
let result = []; let result = [];
async function doQuery(fields) { async function doQuery(_key, fields) {
return await module.client.collection('objects').find(query, { projection: fields }) return await module.client.collection('objects').find({ ...query, ...{ _key: _key } }, { projection: fields })
.sort({ score: sort }) .sort({ score: sort })
.skip(start) .skip(start)
.limit(limit) .limit(limit)
@ -94,14 +94,10 @@ module.exports = function (module) {
const batches = []; const batches = [];
const batch = require('../../batch'); const batch = require('../../batch');
await batch.processArray(key, async currentBatch => batches.push(currentBatch), { batch: 100 }); await batch.processArray(key, async currentBatch => batches.push(currentBatch), { batch: 100 });
const batchData = await Promise.all(batches.map(async (batch) => { const batchData = await Promise.all(batches.map(batch => doQuery({ $in: batch }, { _id: 0, _key: 0 })));
query._key = { $in: batch };
return await doQuery({ _id: 0, _key: 0 });
}));
result = dbHelpers.mergeBatch(batchData, start, stop, sort); result = dbHelpers.mergeBatch(batchData, start, stop, sort);
} else { } else {
result = await doQuery(fields); result = await doQuery(query._key, fields);
} }
if (reverse) { if (reverse) {

Loading…
Cancel
Save