Updated SEARCH UID range queries

This commit is contained in:
Andris Reinman 2017-07-16 23:04:59 +03:00
parent e265cd254e
commit 93ba7f6c8c
2 changed files with 18 additions and 10 deletions

View file

@ -1,6 +1,7 @@
'use strict';
const db = require('../db');
const tools = require('../tools');
/**
* Returns an array of matching UID values
@ -93,9 +94,7 @@ module.exports = server => (path, options, session, callback) => {
if (term.value.length !== session.selected.uidList.length) {
// not 1:*
parent.push({
uid: {
[!ne ? '$in' : '$nin']: term.value
}
uid: tools.checkRangeQuery(term.value, ne)
});
} else if (ne) {
parent.push({

View file

@ -2,28 +2,37 @@
const punycode = require('punycode');
function checkRangeQuery(uids) {
function checkRangeQuery(uids, ne) {
// check if uids is a straight continous array and if such then return a range query,
// otherwise retrun a $in query
if (uids.length === 1) {
return {
$eq: uids[0]
[!ne ? '$eq' : '$ne']: uids[0]
};
}
for (let i = 1, len = uids.length; i < len; i++) {
if (uids[i] !== uids[i - 1] + 1) {
return {
$in: uids
[!ne ? '$in' : '$nin']: uids
};
}
}
return {
$gte: uids[0],
$lte: uids[uids.length - 1]
};
if (!ne) {
return {
$gte: uids[0],
$lte: uids[uids.length - 1]
};
} else {
return {
$not: {
$gte: uids[0],
$lte: uids[uids.length - 1]
}
};
}
}
function normalizeAddress(address, withNames) {