Split netquery package files and update bandwidth chart handler

This commit is contained in:
Patrick Pacher
2023-10-05 10:28:18 +02:00
committed by Daniel
parent bc285b593d
commit 1484591aea
3 changed files with 49 additions and 18 deletions

View File

@@ -19,6 +19,7 @@ type BandwidthChartHandler struct {
}
type BandwidthChartRequest struct {
AllProfiles bool `json:"allProfiles"`
Profiles []string `json:"profiles"`
Connections []string `json:"connections"`
}
@@ -107,18 +108,21 @@ func (req *BandwidthChartRequest) generateSQL(ctx context.Context, schema *orm.T
whereClause := ""
params := make(map[string]any)
if len(req.Profiles) > 0 {
if (len(req.Profiles) > 0) || (req.AllProfiles == true) {
groupBy = []string{"profile", "round(time/10, 0)*10"}
selects = append(selects, "profile")
clauses := make([]string, len(req.Profiles))
for idx, p := range req.Profiles {
key := fmt.Sprintf(":p%d", idx)
clauses[idx] = "profile = " + key
params[key] = p
if !req.AllProfiles {
clauses := make([]string, len(req.Profiles))
for idx, p := range req.Profiles {
key := fmt.Sprintf(":p%d", idx)
clauses[idx] = "profile = " + key
params[key] = p
}
whereClause = "WHERE " + strings.Join(clauses, " OR ")
}
whereClause = "WHERE " + strings.Join(clauses, " OR ")
} else if len(req.Connections) > 0 {
groupBy = []string{"conn_id", "round(time/10, 0)*10"}
selects = append(selects, "conn_id")