mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-17 21:25:58 +08:00
chore: use slices.sort*
This commit is contained in:
parent
10560dc49f
commit
926d6f8e71
@ -3,7 +3,6 @@ package querybuildertypesv5
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"sort"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -221,8 +220,14 @@ func (fe *FormulaEvaluator) buildSeriesKey(variable string, seriesIndex int, lab
|
|||||||
// Sort labels by key name for consistent ordering
|
// Sort labels by key name for consistent ordering
|
||||||
sortedLabels := make([]*Label, len(labels))
|
sortedLabels := make([]*Label, len(labels))
|
||||||
copy(sortedLabels, labels)
|
copy(sortedLabels, labels)
|
||||||
sort.Slice(sortedLabels, func(i, j int) bool {
|
slices.SortFunc(sortedLabels, func(i, j *Label) int {
|
||||||
return sortedLabels[i].Key.Name < sortedLabels[j].Key.Name
|
if i.Key.Name < j.Key.Name {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
if i.Key.Name > j.Key.Name {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
return 0
|
||||||
})
|
})
|
||||||
|
|
||||||
for _, label := range sortedLabels {
|
for _, label := range sortedLabels {
|
||||||
@ -242,8 +247,14 @@ func (fe *FormulaEvaluator) findUniqueLabelSets(lookup *seriesLookup) [][]*Label
|
|||||||
}
|
}
|
||||||
|
|
||||||
// sort the label sets by the number of labels in descending order
|
// sort the label sets by the number of labels in descending order
|
||||||
sort.Slice(allLabelSets, func(i, j int) bool {
|
slices.SortFunc(allLabelSets, func(i, j []*Label) int {
|
||||||
return len(allLabelSets[i]) > len(allLabelSets[j])
|
if len(i) > len(j) {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
if len(i) < len(j) {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
return 0
|
||||||
})
|
})
|
||||||
|
|
||||||
// Find unique label sets using proper label comparison
|
// Find unique label sets using proper label comparison
|
||||||
|
Loading…
x
Reference in New Issue
Block a user