Replace bubble sort with idiomatic sort.Slice in EC shard management

- Replace O(n²) bubble sort implementation with efficient sort.Slice
- More concise, readable, and performant for larger slices
- Uses idiomatic Go sorting pattern
This commit is contained in:
chrislu
2025-08-10 17:52:30 -07:00
parent c9ca213d4c
commit c220ad1e69
+3 -7
View File
@@ -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
}
}