From 42f2417276503407dfae442d67ece852b3418693 Mon Sep 17 00:00:00 2001 From: Mohamed Mahmoud <152813205+Haroka-74@users.noreply.github.com> Date: Mon, 27 Apr 2026 17:50:18 +0300 Subject: [PATCH] perf: use slices instead of bubblesort (#1179) --- fetcher/fetcher.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/fetcher/fetcher.go b/fetcher/fetcher.go index 52b450a63939d7ace3cb2c3fa86c785315674276..01e09503e5db6e6f50316a37b47a474fbae25a00 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