feat: batch.processSortedSet min/max (#12129)

* feat: batch.processSortedSet min/max

* test if this works
This commit is contained in:
Barış Soner Uşaklı
2023-10-26 10:23:27 -04:00
committed by GitHub
parent 075cd598d1
commit 6c7e614417
4 changed files with 50 additions and 3 deletions

View File

@@ -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);

View File

@@ -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);