mirror of
https://github.com/nodemailer/wildduck.git
synced 2025-11-09 16:01:06 +08:00
Updated SEARCH UID range queries
This commit is contained in:
parent
e265cd254e
commit
93ba7f6c8c
2 changed files with 18 additions and 10 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const db = require('../db');
|
const db = require('../db');
|
||||||
|
const tools = require('../tools');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array of matching UID values
|
* 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) {
|
if (term.value.length !== session.selected.uidList.length) {
|
||||||
// not 1:*
|
// not 1:*
|
||||||
parent.push({
|
parent.push({
|
||||||
uid: {
|
uid: tools.checkRangeQuery(term.value, ne)
|
||||||
[!ne ? '$in' : '$nin']: term.value
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
} else if (ne) {
|
} else if (ne) {
|
||||||
parent.push({
|
parent.push({
|
||||||
|
|
|
||||||
23
lib/tools.js
23
lib/tools.js
|
|
@ -2,28 +2,37 @@
|
||||||
|
|
||||||
const punycode = require('punycode');
|
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,
|
// check if uids is a straight continous array and if such then return a range query,
|
||||||
// otherwise retrun a $in query
|
// otherwise retrun a $in query
|
||||||
|
|
||||||
if (uids.length === 1) {
|
if (uids.length === 1) {
|
||||||
return {
|
return {
|
||||||
$eq: uids[0]
|
[!ne ? '$eq' : '$ne']: uids[0]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 1, len = uids.length; i < len; i++) {
|
for (let i = 1, len = uids.length; i < len; i++) {
|
||||||
if (uids[i] !== uids[i - 1] + 1) {
|
if (uids[i] !== uids[i - 1] + 1) {
|
||||||
return {
|
return {
|
||||||
$in: uids
|
[!ne ? '$in' : '$nin']: uids
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
if (!ne) {
|
||||||
$gte: uids[0],
|
return {
|
||||||
$lte: uids[uids.length - 1]
|
$gte: uids[0],
|
||||||
};
|
$lte: uids[uids.length - 1]
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
$not: {
|
||||||
|
$gte: uids[0],
|
||||||
|
$lte: uids[uids.length - 1]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalizeAddress(address, withNames) {
|
function normalizeAddress(address, withNames) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue