mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-28 17:46:16 +01:00
feat: use covered query
This commit is contained in:
@@ -15,16 +15,23 @@ module.exports = function (module) {
|
||||
if (!key) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Array.isArray(key)) {
|
||||
const data = await module.client.collection('objects').find({ _key: { $in: key } }).toArray();
|
||||
var map = {};
|
||||
const data = await module.client.collection('objects').find({
|
||||
_key: { $in: key },
|
||||
}, { _id: 0, _key: 1 }).toArray();
|
||||
|
||||
const map = {};
|
||||
data.forEach(function (item) {
|
||||
map[item._key] = true;
|
||||
});
|
||||
|
||||
return key.map(key => !!map[key]);
|
||||
}
|
||||
const item = await module.client.collection('objects').findOne({ _key: key });
|
||||
|
||||
const item = await module.client.collection('objects').findOne({
|
||||
_key: key,
|
||||
}, { _id: 0, _key: 1 });
|
||||
return item !== undefined && item !== null;
|
||||
};
|
||||
|
||||
@@ -74,15 +81,16 @@ module.exports = function (module) {
|
||||
if (!key) {
|
||||
return;
|
||||
}
|
||||
var data = { data: value };
|
||||
await module.setObject(key, data);
|
||||
await module.setObject(key, { data: value });
|
||||
};
|
||||
|
||||
module.increment = async function (key) {
|
||||
if (!key) {
|
||||
return;
|
||||
}
|
||||
const result = await module.client.collection('objects').findOneAndUpdate({ _key: key }, { $inc: { data: 1 } }, { returnOriginal: false, upsert: true });
|
||||
const result = await module.client.collection('objects').findOneAndUpdate({
|
||||
_key: key,
|
||||
}, { $inc: { data: 1 } }, { returnOriginal: false, upsert: true });
|
||||
return result && result.value ? result.value.data : null;
|
||||
};
|
||||
|
||||
|
||||
@@ -428,7 +428,7 @@ module.exports = function (module) {
|
||||
count = count !== undefined ? count : 0;
|
||||
buildLexQuery(query, min, max);
|
||||
|
||||
const data = await module.client.collection('objects').find(query, { projection: { _id: 0, _key: 0, score: 0 } })
|
||||
const data = await module.client.collection('objects').find(query, { projection: { _id: 0, value: 1 } })
|
||||
.sort({ value: sort })
|
||||
.skip(start)
|
||||
.limit(count === -1 ? 0 : count)
|
||||
|
||||
Reference in New Issue
Block a user