mirror of
https://github.com/nodemailer/wildduck.git
synced 2025-01-01 13:13:53 +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]
|
||||
]);
|
||||
|
||||
let notifyEntries = [];
|
||||
|
||||
let processNext = () => {
|
||||
cursor.next((err, message) => {
|
||||
if (err) {
|
||||
|
@ -464,6 +466,14 @@ server.onStore = function (path, update, session, callback) {
|
|||
}
|
||||
if (!message) {
|
||||
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);
|
||||
return callback(null, true);
|
||||
});
|
||||
|
@ -531,15 +541,34 @@ server.onStore = function (path, update, session, callback) {
|
|||
_id: message._id
|
||||
}, flagsupdate, {}, 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',
|
||||
ignore: session.id,
|
||||
uid: message.uid,
|
||||
flags: message.flags,
|
||||
message: message._id
|
||||
}, processNext);
|
||||
});
|
||||
|
||||
if (notifyEntries.length > 100) {
|
||||
setImmediate(() => this.notifier.addEntries(username, path, notifyEntries, processNext));
|
||||
notifyEntries = [];
|
||||
return;
|
||||
}
|
||||
setImmediate(() => processNext());
|
||||
});
|
||||
} else {
|
||||
processNext();
|
||||
|
|
Loading…
Reference in a new issue