From 8a16db8f3022c1b6e33cb06e76344af11c8d90db Mon Sep 17 00:00:00 2001 From: Marcin Czenko Date: Thu, 23 Oct 2025 02:06:05 +0200 Subject: [PATCH] use go library function for sorting --- communities/codex_archive_downloader.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/communities/codex_archive_downloader.go b/communities/codex_archive_downloader.go index b8a593f..2942683 100644 --- a/communities/codex_archive_downloader.go +++ b/communities/codex_archive_downloader.go @@ -154,14 +154,16 @@ func (d *CodexArchiveDownloader) downloadAllArchives() { }) } - // Sort by timestamp (newest first) - same as torrent version - for i := 0; i < len(archivesList)-1; i++ { - for j := i + 1; j < len(archivesList); j++ { - if archivesList[i].from < archivesList[j].from { - archivesList[i], archivesList[j] = archivesList[j], archivesList[i] - } + // Sort by timestamp (newest first) + slices.SortFunc(archivesList, func(a, b archiveInfo) int { + if a.from > b.from { + return -1 // a is newer, should come first } - } + if a.from < b.from { + return 1 // b is newer, should come first + } + return 0 // equal timestamps + }) // Monitor for cancellation in a separate goroutine go func() {