Improve mail deletion speed en masse

This commit is contained in:
ClaraCrazy 2025-12-15 04:51:54 +01:00
parent 2ac2371963
commit b80db9fbd3
No known key found for this signature in database
GPG key ID: EBBC896ACB497011

View file

@ -47,16 +47,28 @@ class MailRepository {
removeUid(uid, address) { removeUid(uid, address) {
if (!this.config.email.examples.uids.includes(parseInt(uid))) { if (!this.config.email.examples.uids.includes(parseInt(uid))) {
var deleted = false var deleted = false
// TODO: make this more efficient, looping through each email is not cool.
this.mailSummaries.forEachAssociation((mails, to) => { if (address) {
mails // Efficient path: only search the specific address's emails
.filter(mail => mail.uid === parseInt(uid) && (address ? to == address : true)) const mails = this.mailSummaries.get(address) || []
.forEach(mail => { const mailToDelete = mails.find(mail => mail.uid === parseInt(uid))
this.mailSummaries.remove(to, mail) if (mailToDelete) {
debug('Removed ', mail.date, to, mail.subject) this.mailSummaries.remove(address, mailToDelete)
deleted = true debug('Removed ', mailToDelete.date, address, mailToDelete.subject)
}) deleted = true
}) }
} else {
// Fallback: search all emails (needed when address is unknown)
this.mailSummaries.forEachAssociation((mails, to) => {
mails
.filter(mail => mail.uid === parseInt(uid))
.forEach(mail => {
this.mailSummaries.remove(to, mail)
debug('Removed ', mail.date, to, mail.subject)
deleted = true
})
})
}
return deleted return deleted
} }
return false return false