Browse Source

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
add-ec-vacuum
chrislu 4 months ago
parent
commit
c220ad1e69
  1. 10
      weed/admin/dash/ec_shard_management.go

10
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
}
}

Loading…
Cancel
Save