From f575b5385482b8036e2cd34c73ba132332e1b38e Mon Sep 17 00:00:00 2001 From: Ralph Slooten Date: Sat, 9 May 2026 16:43:40 +1200 Subject: [PATCH] Chore: Refactor pruneMessages function to eliminate duplicate ID checks using a map --- internal/storage/cron.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/storage/cron.go b/internal/storage/cron.go index 52b29d7..6866b68 100644 --- a/internal/storage/cron.go +++ b/internal/storage/cron.go @@ -9,7 +9,6 @@ import ( "github.com/axllent/mailpit/config" "github.com/axllent/mailpit/internal/logger" - "github.com/axllent/mailpit/internal/tools" "github.com/axllent/mailpit/server/websockets" "github.com/leporo/sqlf" ) @@ -64,6 +63,7 @@ func pruneMessages() { start := time.Now() ids := []string{} + idsSeen := make(map[string]bool) var prunedSize uint64 var size float64 // use float64 for rqlite compatibility @@ -88,6 +88,7 @@ func pruneMessages() { return } ids = append(ids, id) + idsSeen[id] = true prunedSize = prunedSize + uint64(size) }, @@ -115,8 +116,9 @@ func pruneMessages() { return } - if !tools.InArray(id, ids) { + if _, exists := idsSeen[id]; !exists { ids = append(ids, id) + idsSeen[id] = true prunedSize = prunedSize + uint64(size) }