mirror of
https://github.com/nodemailer/wildduck.git
synced 2025-01-06 08:02:27 +08:00
emit flag update notifications in chunks of 100
This commit is contained in:
parent
c5f3fee871
commit
d6b028997f
1 changed files with 32 additions and 3 deletions
35
imap.js
35
imap.js
|
@ -457,6 +457,8 @@ server.onStore = function (path, update, session, callback) {
|
||||||
['uid', 1]
|
['uid', 1]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
let notifyEntries = [];
|
||||||
|
|
||||||
let processNext = () => {
|
let processNext = () => {
|
||||||
cursor.next((err, message) => {
|
cursor.next((err, message) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -464,6 +466,14 @@ server.onStore = function (path, update, session, callback) {
|
||||||
}
|
}
|
||||||
if (!message) {
|
if (!message) {
|
||||||
return cursor.close(() => {
|
return cursor.close(() => {
|
||||||
|
if (notifyEntries.length) {
|
||||||
|
setImmediate(() => this.notifier.addEntries(username, path, notifyEntries, () => {
|
||||||
|
this.notifier.fire(username, path);
|
||||||
|
return callback(null, true);
|
||||||
|
}));
|
||||||
|
notifyEntries = [];
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.notifier.fire(username, path);
|
this.notifier.fire(username, path);
|
||||||
return callback(null, true);
|
return callback(null, true);
|
||||||
});
|
});
|
||||||
|
@ -531,15 +541,34 @@ server.onStore = function (path, update, session, callback) {
|
||||||
_id: message._id
|
_id: message._id
|
||||||
}, flagsupdate, {}, err => {
|
}, flagsupdate, {}, err => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return cursor.close(() => callback(err));
|
return cursor.close(() => {
|
||||||
|
if (notifyEntries.length) {
|
||||||
|
setImmediate(() => this.notifier.addEntries(username, path, notifyEntries, () => {
|
||||||
|
this.notifier.fire(username, path);
|
||||||
|
return callback(err);
|
||||||
|
}));
|
||||||
|
notifyEntries = [];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.notifier.fire(username, path);
|
||||||
|
callback(err);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
this.notifier.addEntries(username, path, {
|
|
||||||
|
notifyEntries.push({
|
||||||
command: 'FETCH',
|
command: 'FETCH',
|
||||||
ignore: session.id,
|
ignore: session.id,
|
||||||
uid: message.uid,
|
uid: message.uid,
|
||||||
flags: message.flags,
|
flags: message.flags,
|
||||||
message: message._id
|
message: message._id
|
||||||
}, processNext);
|
});
|
||||||
|
|
||||||
|
if (notifyEntries.length > 100) {
|
||||||
|
setImmediate(() => this.notifier.addEntries(username, path, notifyEntries, processNext));
|
||||||
|
notifyEntries = [];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setImmediate(() => processNext());
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
processNext();
|
processNext();
|
||||||
|
|
Loading…
Reference in a new issue