mirror of
https://github.com/Crazyco-xyz/48hr.email.git
synced 2025-12-16 06:46:33 +01:00
Improve mail deletion speed en masse
This commit is contained in:
parent
2ac2371963
commit
b80db9fbd3
1 changed files with 22 additions and 10 deletions
|
|
@ -47,16 +47,28 @@ class MailRepository {
|
|||
removeUid(uid, address) {
|
||||
if (!this.config.email.examples.uids.includes(parseInt(uid))) {
|
||||
var deleted = false
|
||||
// TODO: make this more efficient, looping through each email is not cool.
|
||||
this.mailSummaries.forEachAssociation((mails, to) => {
|
||||
mails
|
||||
.filter(mail => mail.uid === parseInt(uid) && (address ? to == address : true))
|
||||
.forEach(mail => {
|
||||
this.mailSummaries.remove(to, mail)
|
||||
debug('Removed ', mail.date, to, mail.subject)
|
||||
deleted = true
|
||||
})
|
||||
})
|
||||
|
||||
if (address) {
|
||||
// Efficient path: only search the specific address's emails
|
||||
const mails = this.mailSummaries.get(address) || []
|
||||
const mailToDelete = mails.find(mail => mail.uid === parseInt(uid))
|
||||
if (mailToDelete) {
|
||||
this.mailSummaries.remove(address, mailToDelete)
|
||||
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 false
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue