From c220ad1e693821d98d01523af56d55bf6cb69281 Mon Sep 17 00:00:00 2001 From: chrislu Date: Sun, 10 Aug 2025 17:52:30 -0700 Subject: [PATCH] Replace bubble sort with idiomatic sort.Slice in EC shard management MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Replace O(n²) bubble sort implementation with efficient sort.Slice - More concise, readable, and performant for larger slices - Uses idiomatic Go sorting pattern --- weed/admin/dash/ec_shard_management.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/weed/admin/dash/ec_shard_management.go b/weed/admin/dash/ec_shard_management.go index 02138e9e7..eb72d34ac 100644 --- a/weed/admin/dash/ec_shard_management.go +++ b/weed/admin/dash/ec_shard_management.go @@ -414,13 +414,9 @@ func (s *AdminServer) GetClusterEcVolumes(page int, pageSize int, sortBy string, // Sort generations and check for multiple generations if len(volume.Generations) > 1 { // Sort generations (oldest first) - for i := 0; i < len(volume.Generations); i++ { - for j := i + 1; j < len(volume.Generations); j++ { - if volume.Generations[i] > volume.Generations[j] { - volume.Generations[i], volume.Generations[j] = volume.Generations[j], volume.Generations[i] - } - } - } + sort.Slice(volume.Generations, func(i, j int) bool { + return volume.Generations[i] < volume.Generations[j] + }) volume.HasMultipleGenerations = true } }