Use UID-stable target dedup scan
This commit is contained in:
parent
b16deffa25
commit
8e8c651eaa
3 changed files with 64 additions and 17 deletions
|
|
@ -13,6 +13,7 @@ type TargetDedupReport struct {
|
|||
Folders int
|
||||
Groups int
|
||||
ExtraCopies int
|
||||
Candidates int
|
||||
WithoutID int
|
||||
Deleted int
|
||||
FolderReports []TargetDedupFolderReport
|
||||
|
|
@ -58,6 +59,7 @@ func DedupTarget(name string, folders []string, apply bool) (TargetDedupReport,
|
|||
report.Folders++
|
||||
report.Groups += folderReport.Groups
|
||||
report.ExtraCopies += folderReport.ExtraCopies
|
||||
report.Candidates += len(folderReport.Deletes)
|
||||
report.WithoutID += folderReport.WithoutID
|
||||
if apply {
|
||||
report.Deleted += len(folderReport.Deletes)
|
||||
|
|
@ -65,29 +67,24 @@ func DedupTarget(name string, folders []string, apply bool) (TargetDedupReport,
|
|||
report.FolderReports = append(report.FolderReports, folderReport)
|
||||
}
|
||||
log.Printf("target dedup %s apply=%v folders=%d groups=%d extra=%d candidates=%d deleted=%d without_id=%d",
|
||||
report.Account, report.Apply, report.Folders, report.Groups, report.ExtraCopies, report.ExtraCopies, report.Deleted, report.WithoutID)
|
||||
report.Account, report.Apply, report.Folders, report.Groups, report.ExtraCopies, report.Candidates, report.Deleted, report.WithoutID)
|
||||
return report, nil
|
||||
}
|
||||
|
||||
func dedupTargetFolder(dst TargetMailbox, folder string, apply bool) (TargetDedupFolderReport, error) {
|
||||
report := TargetDedupFolderReport{Folder: folder}
|
||||
byID := map[string][]uint32{}
|
||||
for offset := 0; ; offset += mailboxListLimit {
|
||||
headers, err := dst.Headers(folder, mailboxListLimit, offset)
|
||||
if err != nil {
|
||||
return report, fmt.Errorf("%s headers: %w", folder, err)
|
||||
}
|
||||
if len(headers) == 0 {
|
||||
break
|
||||
}
|
||||
for _, header := range headers {
|
||||
id := normalizeMessageID(header.MessageID)
|
||||
if id == "" {
|
||||
report.WithoutID++
|
||||
continue
|
||||
}
|
||||
byID[id] = append(byID[id], header.UID)
|
||||
headers, err := dst.AllHeaders(folder)
|
||||
if err != nil {
|
||||
return report, fmt.Errorf("%s headers: %w", folder, err)
|
||||
}
|
||||
for _, header := range headers {
|
||||
id := normalizeMessageID(header.MessageID)
|
||||
if id == "" {
|
||||
report.WithoutID++
|
||||
continue
|
||||
}
|
||||
byID[id] = append(byID[id], header.UID)
|
||||
}
|
||||
var deleteUIDs []uint32
|
||||
for id, uids := range byID {
|
||||
|
|
@ -129,7 +126,7 @@ func LogTargetDedupReport(report TargetDedupReport) {
|
|||
mode = "APPLY"
|
||||
}
|
||||
log.Printf("target dedup report %s account=%s folders=%d groups=%d extra=%d candidates=%d deleted=%d without_id=%d",
|
||||
mode, report.Account, report.Folders, report.Groups, report.ExtraCopies, report.ExtraCopies, report.Deleted, report.WithoutID)
|
||||
mode, report.Account, report.Folders, report.Groups, report.ExtraCopies, report.Candidates, report.Deleted, report.WithoutID)
|
||||
for _, folder := range report.FolderReports {
|
||||
if folder.Groups == 0 && folder.WithoutID == 0 {
|
||||
continue
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue