mirror of
https://github.com/nodemailer/wildduck.git
synced 2025-10-26 05:56:59 +08:00
use index for sorting
This commit is contained in:
parent
3ad81e4fa9
commit
e42a128ee6
4 changed files with 32 additions and 29 deletions
28
api.js
28
api.js
|
|
@ -732,9 +732,10 @@ server.get('/mailbox/:id', (req, res, next) => {
|
||||||
mailbox: mailbox._id
|
mailbox: mailbox._id
|
||||||
};
|
};
|
||||||
let reverse = false;
|
let reverse = false;
|
||||||
let sort = {
|
let sort = [
|
||||||
uid: -1
|
['mailbox', 1],
|
||||||
};
|
['uid', -1]
|
||||||
|
];
|
||||||
|
|
||||||
if (req.params.before) {
|
if (req.params.before) {
|
||||||
query.uid = {
|
query.uid = {
|
||||||
|
|
@ -744,9 +745,10 @@ server.get('/mailbox/:id', (req, res, next) => {
|
||||||
query.uid = {
|
query.uid = {
|
||||||
$gt: after
|
$gt: after
|
||||||
};
|
};
|
||||||
sort = {
|
sort = [
|
||||||
uid: 1
|
['mailbox', 1],
|
||||||
};
|
['uid', 1]
|
||||||
|
];
|
||||||
reverse = true;
|
reverse = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -756,9 +758,10 @@ server.get('/mailbox/:id', (req, res, next) => {
|
||||||
fields: {
|
fields: {
|
||||||
uid: true
|
uid: true
|
||||||
},
|
},
|
||||||
sort: {
|
sort: [
|
||||||
uid: -1
|
['mailbox', 1],
|
||||||
}
|
['uid', -1]
|
||||||
|
]
|
||||||
}, (err, entry) => {
|
}, (err, entry) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
res.json({
|
res.json({
|
||||||
|
|
@ -790,9 +793,10 @@ server.get('/mailbox/:id', (req, res, next) => {
|
||||||
fields: {
|
fields: {
|
||||||
uid: true
|
uid: true
|
||||||
},
|
},
|
||||||
sort: {
|
sort: [
|
||||||
uid: 1
|
['mailbox', 1],
|
||||||
}
|
['uid', 1]
|
||||||
|
]
|
||||||
}, (err, entry) => {
|
}, (err, entry) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
res.json({
|
res.json({
|
||||||
|
|
|
||||||
7
imap.js
7
imap.js
|
|
@ -319,6 +319,7 @@ server.onOpen = function (path, session, callback) {
|
||||||
}).project({
|
}).project({
|
||||||
uid: true
|
uid: true
|
||||||
}).sort([
|
}).sort([
|
||||||
|
['mailbox', 1],
|
||||||
['uid', 1]
|
['uid', 1]
|
||||||
]).toArray((err, messages) => {
|
]).toArray((err, messages) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
@ -476,6 +477,7 @@ server.onStore = function (path, update, session, callback) {
|
||||||
uid: true,
|
uid: true,
|
||||||
flags: true
|
flags: true
|
||||||
}).sort([
|
}).sort([
|
||||||
|
['mailbox', 1],
|
||||||
['uid', 1]
|
['uid', 1]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
@ -661,6 +663,7 @@ server.onExpunge = function (path, update, session, callback) {
|
||||||
uid: true,
|
uid: true,
|
||||||
size: true
|
size: true
|
||||||
}).sort([
|
}).sort([
|
||||||
|
['mailbox', 1],
|
||||||
['uid', 1]
|
['uid', 1]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
@ -781,6 +784,7 @@ server.onCopy = function (path, update, session, callback) {
|
||||||
$in: update.messages
|
$in: update.messages
|
||||||
}
|
}
|
||||||
}).sort([
|
}).sort([
|
||||||
|
['mailbox', 1],
|
||||||
['uid', 1]
|
['uid', 1]
|
||||||
]); // no projection as we need to copy the entire message
|
]); // no projection as we need to copy the entire message
|
||||||
|
|
||||||
|
|
@ -925,6 +929,7 @@ server.onMove = function (path, update, session, callback) {
|
||||||
}).project({
|
}).project({
|
||||||
uid: 1
|
uid: 1
|
||||||
}).sort([
|
}).sort([
|
||||||
|
['mailbox', 1],
|
||||||
['uid', 1]
|
['uid', 1]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
@ -1064,6 +1069,7 @@ server.onFetch = function (path, options, session, callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
let cursor = db.database.collection('messages').find(query).project(projection).sort([
|
let cursor = db.database.collection('messages').find(query).project(projection).sort([
|
||||||
|
['mailbox', 1],
|
||||||
['uid', 1]
|
['uid', 1]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
@ -1429,6 +1435,7 @@ server.onSearch = function (path, options, session, callback) {
|
||||||
let cursor = db.database.collection('messages').find(query).
|
let cursor = db.database.collection('messages').find(query).
|
||||||
project(projection).
|
project(projection).
|
||||||
sort([
|
sort([
|
||||||
|
['mailbox', 1],
|
||||||
['uid', 1]
|
['uid', 1]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -279,12 +279,12 @@ class ImapNotifier extends EventEmitter {
|
||||||
modseq: {
|
modseq: {
|
||||||
$gt: modifyIndex
|
$gt: modifyIndex
|
||||||
}
|
}
|
||||||
}).sort({
|
}).sort([
|
||||||
modseq: 1
|
['mailbox', 1],
|
||||||
}).toArray(callback);
|
['modseq', 1]
|
||||||
|
]).toArray(callback);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = ImapNotifier;
|
module.exports = ImapNotifier;
|
||||||
|
|
|
||||||
|
|
@ -122,8 +122,7 @@ class MessageHandler {
|
||||||
_id: mailbox.user
|
_id: mailbox.user
|
||||||
}, {
|
}, {
|
||||||
$inc: {
|
$inc: {
|
||||||
storageUsed: size,
|
storageUsed: size
|
||||||
messages: 1
|
|
||||||
}
|
}
|
||||||
}, err => {
|
}, err => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
@ -136,8 +135,7 @@ class MessageHandler {
|
||||||
_id: mailbox.user
|
_id: mailbox.user
|
||||||
}, {
|
}, {
|
||||||
$inc: {
|
$inc: {
|
||||||
storageUsed: -size,
|
storageUsed: -size
|
||||||
messages: -1
|
|
||||||
}
|
}
|
||||||
}, () => {
|
}, () => {
|
||||||
this.redlock.releaseLock(lock, () => callback(err));
|
this.redlock.releaseLock(lock, () => callback(err));
|
||||||
|
|
@ -253,24 +251,19 @@ class MessageHandler {
|
||||||
|
|
||||||
updateQuota(mailbox, inc, callback) {
|
updateQuota(mailbox, inc, callback) {
|
||||||
inc = inc || {};
|
inc = inc || {};
|
||||||
if (!inc.messages) {
|
|
||||||
return callback();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.database.collection('mailboxes').findOneAndUpdate({
|
this.database.collection('mailboxes').findOneAndUpdate({
|
||||||
_id: mailbox._id
|
_id: mailbox._id
|
||||||
}, {
|
}, {
|
||||||
$inc: {
|
$inc: {
|
||||||
storageUsed: Number(inc.storageUsed) || 0,
|
storageUsed: Number(inc.storageUsed) || 0
|
||||||
messages: Number(inc.messages) || 0
|
|
||||||
}
|
}
|
||||||
}, () => {
|
}, () => {
|
||||||
this.database.collection('users').findOneAndUpdate({
|
this.database.collection('users').findOneAndUpdate({
|
||||||
_id: mailbox.user
|
_id: mailbox.user
|
||||||
}, {
|
}, {
|
||||||
$inc: {
|
$inc: {
|
||||||
storageUsed: Number(inc.storageUsed) || 0,
|
storageUsed: Number(inc.storageUsed) || 0
|
||||||
messages: Number(inc.messages) || 0
|
|
||||||
}
|
}
|
||||||
}, callback);
|
}, callback);
|
||||||
});
|
});
|
||||||
|
|
@ -305,8 +298,7 @@ class MessageHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updateQuota(mailbox, {
|
this.updateQuota(mailbox, {
|
||||||
storageUsed: -message.size,
|
storageUsed: -message.size
|
||||||
messages: -1
|
|
||||||
}, () => {
|
}, () => {
|
||||||
// remove link to message from attachments (if any exist)
|
// remove link to message from attachments (if any exist)
|
||||||
this.database.collection('attachments.files').updateMany({
|
this.database.collection('attachments.files').updateMany({
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue