mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-17 03:01:08 +01:00
feat: batch.processSortedSet min/max (#12129)
* feat: batch.processSortedSet min/max * test if this works
This commit is contained in:
committed by
GitHub
parent
075cd598d1
commit
6c7e614417
@@ -568,7 +568,17 @@ module.exports = function (module) {
|
||||
if (!options.withScores) {
|
||||
project.score = 0;
|
||||
}
|
||||
const cursor = await module.client.collection('objects').find({ _key: setKey }, { projection: project })
|
||||
const query = { _key: setKey };
|
||||
if (options.min && options.min !== '-inf') {
|
||||
query.score = { $gte: parseFloat(options.min) };
|
||||
}
|
||||
if (options.max && options.max !== '+inf') {
|
||||
query.score = query.score || {};
|
||||
query.score.$lte = parseFloat(options.max);
|
||||
}
|
||||
|
||||
const cursor = await module.client.collection('objects')
|
||||
.find(query, { projection: project })
|
||||
.sort({ score: sort })
|
||||
.batchSize(options.batch);
|
||||
|
||||
|
||||
@@ -665,6 +665,8 @@ SELECT z."value",
|
||||
const client = await module.pool.connect();
|
||||
const batchSize = (options || {}).batch || 100;
|
||||
const sort = options.reverse ? 'DESC' : 'ASC';
|
||||
const min = options.min && options.min !== '-inf' ? options.min : null;
|
||||
const max = options.max && options.max !== '+inf' ? options.max : null;
|
||||
const cursor = client.query(new Cursor(`
|
||||
SELECT z."value", z."score"
|
||||
FROM "legacy_object_live" o
|
||||
@@ -672,7 +674,9 @@ SELECT z."value", z."score"
|
||||
ON o."_key" = z."_key"
|
||||
AND o."type" = z."type"
|
||||
WHERE o."_key" = $1::TEXT
|
||||
ORDER BY z."score" ${sort}, z."value" ${sort}`, [setKey]));
|
||||
AND (z."score" >= $2::NUMERIC OR $2::NUMERIC IS NULL)
|
||||
AND (z."score" <= $3::NUMERIC OR $3::NUMERIC IS NULL)
|
||||
ORDER BY z."score" ${sort}, z."value" ${sort}`, [setKey, min, max]));
|
||||
|
||||
if (process && process.constructor && process.constructor.name !== 'AsyncFunction') {
|
||||
process = util.promisify(process);
|
||||
|
||||
Reference in New Issue
Block a user