mirror of
https://github.com/nodemailer/wildduck.git
synced 2025-01-03 06:18:45 +08:00
Cancel deleting expired messages when it takes too long
This commit is contained in:
parent
61347a5c9e
commit
e5d739d84f
1 changed files with 22 additions and 14 deletions
36
imap.js
36
imap.js
|
@ -1968,9 +1968,10 @@ function deleteOrphanedAttachments(callback) {
|
||||||
|
|
||||||
function clearExpiredMessages() {
|
function clearExpiredMessages() {
|
||||||
clearTimeout(gcTimeout);
|
clearTimeout(gcTimeout);
|
||||||
|
let startTime = Date.now();
|
||||||
|
|
||||||
// First, acquire the lock. This prevents multiple connected clients for deleting the same messages
|
// First, acquire the lock. This prevents multiple connected clients for deleting the same messages
|
||||||
gcLock.acquireLock('gc_expired', 3 * 60 * 60 * 1000 /* Lock expires after 61min if not released */, (err, lock) => {
|
gcLock.acquireLock('gc_expired', 3 * 60 * 60 * 1000 /* Lock expires after 3 hours if not released */, (err, lock) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
server.logger.error(
|
server.logger.error(
|
||||||
{
|
{
|
||||||
|
@ -2024,25 +2025,32 @@ function clearExpiredMessages() {
|
||||||
});
|
});
|
||||||
|
|
||||||
let deleted = 0;
|
let deleted = 0;
|
||||||
|
let clear = () =>
|
||||||
|
cursor.close(() => {
|
||||||
|
// delete all attachments that do not have any active links to message objects
|
||||||
|
deleteOrphanedAttachments(() => {
|
||||||
|
server.logger.debug(
|
||||||
|
{
|
||||||
|
tnx: 'gc'
|
||||||
|
},
|
||||||
|
'Deleted %s messages',
|
||||||
|
deleted
|
||||||
|
);
|
||||||
|
done(null, true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
let processNext = () => {
|
let processNext = () => {
|
||||||
|
if (Date.now() - startTime > GC_INTERVAL * 0.8) {
|
||||||
|
return clear();
|
||||||
|
}
|
||||||
|
|
||||||
cursor.next((err, message) => {
|
cursor.next((err, message) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return done(err);
|
return done(err);
|
||||||
}
|
}
|
||||||
if (!message) {
|
if (!message) {
|
||||||
return cursor.close(() => {
|
return clear();
|
||||||
// delete all attachments that do not have any active links to message objects
|
|
||||||
deleteOrphanedAttachments(() => {
|
|
||||||
server.logger.debug(
|
|
||||||
{
|
|
||||||
tnx: 'gc'
|
|
||||||
},
|
|
||||||
'Deleted %s messages',
|
|
||||||
deleted
|
|
||||||
);
|
|
||||||
done(null, true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
server.logger.info(
|
server.logger.info(
|
||||||
|
|
Loading…
Reference in a new issue