mirror of
https://github.com/nodemailer/wildduck.git
synced 2025-01-27 10:18:25 +08:00
log api search queries
This commit is contained in:
parent
aca4c7b1ac
commit
a44a946496
5 changed files with 84 additions and 3 deletions
16
indexes.yaml
16
indexes.yaml
|
@ -313,7 +313,7 @@ indexes:
|
|||
headers.value: text
|
||||
text: text
|
||||
partialFilterExpression:
|
||||
searchable: true
|
||||
searchable: true # ignore messages marked with \Deleted flag
|
||||
|
||||
- collection: messages
|
||||
index:
|
||||
|
@ -583,3 +583,17 @@ indexes:
|
|||
key:
|
||||
metadata.audit: 1
|
||||
metadata.date: 1
|
||||
|
||||
- collection: audit.files
|
||||
type: gridfs # index applies to gridfs database
|
||||
index:
|
||||
name: audit_files_queue
|
||||
key:
|
||||
metadata.info.queueId: 1
|
||||
|
||||
- collection: audit.files
|
||||
type: gridfs # index applies to gridfs database
|
||||
index:
|
||||
name: audit_files_expire
|
||||
key:
|
||||
metadata.info.expires: 1
|
||||
|
|
|
@ -1064,6 +1064,7 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler) => {
|
|||
}
|
||||
|
||||
let total = await getFilteredMessageCount(filter);
|
||||
log.debug('API', 'Searching %s', JSON.stringify(filter));
|
||||
|
||||
let opts = {
|
||||
limit,
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
const ObjectID = require('mongodb').ObjectID;
|
||||
const GridFSBucket = require('mongodb').GridFSBucket;
|
||||
const log = require('npmlog');
|
||||
|
||||
class AuditHandler {
|
||||
constructor(options) {
|
||||
|
@ -172,6 +173,60 @@ class AuditHandler {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
async updateDeliveryStatus(queueId, seq, status, info) {
|
||||
await this.gridfs.collection('audit.files').update(
|
||||
{ 'metadata.info.queueId': queueId },
|
||||
{
|
||||
$push: {
|
||||
'metadata.info.delivery': {
|
||||
seq,
|
||||
status,
|
||||
time: new Date(),
|
||||
info
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
async removeAudit(auditData) {
|
||||
let cursor = await this.gridfs.collection('audit.files').find({
|
||||
'metadata.audit': auditData._id
|
||||
});
|
||||
|
||||
let messages = 0;
|
||||
let messageData;
|
||||
while ((messageData = await cursor.next())) {
|
||||
try {
|
||||
await this.gridstore.delete(messageData._id);
|
||||
messages++;
|
||||
} catch (err) {
|
||||
log.error('Audit', 'Failed to delete message %s. %s', messageData._id, err.message);
|
||||
}
|
||||
}
|
||||
await cursor.close();
|
||||
|
||||
await this.database.collection('audits').deleteOne({ _id: auditData._id });
|
||||
log.info('Audit', 'Deleted expired audit %s (%s messages)', auditData._id, messages);
|
||||
}
|
||||
|
||||
async cleanExpired() {
|
||||
let expiredAudits = await this.database
|
||||
.collection('audits')
|
||||
.find({
|
||||
expires: { $lt: new Date() }
|
||||
})
|
||||
.toArray();
|
||||
|
||||
for (let auditData of expiredAudits) {
|
||||
try {
|
||||
await this.removeAudit(auditData);
|
||||
} catch (err) {
|
||||
log.error('Audit', 'Failed to delete expired audit %s. %s', auditData._id, err.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AuditHandler;
|
||||
|
|
|
@ -235,7 +235,7 @@ class MessageHandler {
|
|||
|
||||
if (maildata.attachments && maildata.attachments.length) {
|
||||
messageData.attachments = maildata.attachments;
|
||||
messageData.ha = !!maildata.attachments.find(a => !a.related);
|
||||
messageData.ha = maildata.attachments.some(a => !a.related);
|
||||
} else {
|
||||
messageData.ha = false;
|
||||
}
|
||||
|
|
13
tasks.js
13
tasks.js
|
@ -318,7 +318,18 @@ function clearExpiredMessages() {
|
|||
if (deleted) {
|
||||
log.verbose('GC', 'Purged %s messages', deleted);
|
||||
}
|
||||
return deleteOrphaned(next);
|
||||
return deleteOrphaned(() => {
|
||||
auditHandler
|
||||
.cleanExpired()
|
||||
.then(() => {
|
||||
try {
|
||||
next();
|
||||
} catch (err) {
|
||||
// ignore, only needed to prevent calling next() twice
|
||||
}
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
});
|
||||
|
||||
let processNext = () => {
|
||||
|
|
Loading…
Reference in a new issue