Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions backend/app/repositories/telemetry/duckdb/endpoint.repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -823,27 +823,29 @@ func sortEndpointStats(stats []models.EndpointStats, orderBy string, sortDirecti
desc := sortDirection != "asc"

sort.Slice(stats, func(i, j int) bool {
var less bool
// Descending is the ascending comparison with the operands swapped.
// Negating the ascending result instead would return true for both
// (i, j) and (j, i) whenever two rows tie, which is not the strict
// weak ordering sort.Slice documents a requirement for.
if desc {
i, j = j, i
}
switch orderBy {
case "count":
less = stats[i].Count < stats[j].Count
return stats[i].Count < stats[j].Count
case "p50_duration":
less = stats[i].P50Duration < stats[j].P50Duration
return stats[i].P50Duration < stats[j].P50Duration
case "p95_duration":
less = stats[i].P95Duration < stats[j].P95Duration
return stats[i].P95Duration < stats[j].P95Duration
case "p99_duration":
less = stats[i].P99Duration < stats[j].P99Duration
return stats[i].P99Duration < stats[j].P99Duration
case "avg_duration":
less = stats[i].AvgDuration < stats[j].AvgDuration
return stats[i].AvgDuration < stats[j].AvgDuration
case "last_seen":
less = stats[i].LastSeen.Before(stats[j].LastSeen)
return stats[i].LastSeen.Before(stats[j].LastSeen)
default:
less = stats[i].Impact < stats[j].Impact
}
if desc {
return !less
return stats[i].Impact < stats[j].Impact
}
return less
})
}

Expand Down
26 changes: 14 additions & 12 deletions backend/app/repositories/telemetry/sqlite/endpoint.repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -856,27 +856,29 @@ func sortEndpointStats(stats []models.EndpointStats, orderBy string, sortDirecti
desc := sortDirection != "asc"

sort.Slice(stats, func(i, j int) bool {
var less bool
// Descending is the ascending comparison with the operands swapped.
// Negating the ascending result instead would return true for both
// (i, j) and (j, i) whenever two rows tie, which is not the strict
// weak ordering sort.Slice documents a requirement for.
if desc {
i, j = j, i
}
switch orderBy {
case "count":
less = stats[i].Count < stats[j].Count
return stats[i].Count < stats[j].Count
case "p50_duration":
less = stats[i].P50Duration < stats[j].P50Duration
return stats[i].P50Duration < stats[j].P50Duration
case "p95_duration":
less = stats[i].P95Duration < stats[j].P95Duration
return stats[i].P95Duration < stats[j].P95Duration
case "p99_duration":
less = stats[i].P99Duration < stats[j].P99Duration
return stats[i].P99Duration < stats[j].P99Duration
case "avg_duration":
less = stats[i].AvgDuration < stats[j].AvgDuration
return stats[i].AvgDuration < stats[j].AvgDuration
case "last_seen":
less = stats[i].LastSeen.Before(stats[j].LastSeen)
return stats[i].LastSeen.Before(stats[j].LastSeen)
default:
less = stats[i].Impact < stats[j].Impact
}
if desc {
return !less
return stats[i].Impact < stats[j].Impact
}
return less
})
}

Expand Down
Loading