From adb7735a107076153aa58a314f62b4e8480d8228 Mon Sep 17 00:00:00 2001 From: Haroka-74 Date: Mon, 27 Apr 2026 16:04:47 +0300 Subject: [PATCH] refactor(fetcher): replace manual O(n^2) sort with sort.Slice --- fetcher/fetcher.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/fetcher/fetcher.go b/fetcher/fetcher.go index 52b450a..01e0950 100644 --- a/fetcher/fetcher.go +++ b/fetcher/fetcher.go @@ -17,6 +17,7 @@ import ( "net/textproto" "os" "slices" + "sort" "strings" "sync" "time" @@ -502,13 +503,9 @@ func FetchMailboxEmails(account *config.Account, mailbox string, limit, offset u } // Sort batch Newest -> Oldest by UID desc - for i := 0; i < len(batchEmails); i++ { - for j := i + 1; j < len(batchEmails); j++ { - if batchEmails[j].UID > batchEmails[i].UID { - batchEmails[i], batchEmails[j] = batchEmails[j], batchEmails[i] - } - } - } + sort.Slice(batchEmails, func(i, j int) bool { + return batchEmails[i].UID > batchEmails[j].UID + }) allEmails = append(allEmails, batchEmails...) cursor = from - 1