mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2026-03-10 18:17:30 +01:00
Optimize queries on footprint attributes
Entire-Checkpoint: 81bf5e62e311
This commit is contained in:
@@ -63,12 +63,11 @@ func (r *JobRepository) QueryJobs(
|
||||
}
|
||||
} else {
|
||||
// Order by footprint JSON field values
|
||||
query = query.Where("JSON_VALID(meta_data)")
|
||||
switch order.Order {
|
||||
case model.SortDirectionEnumAsc:
|
||||
query = query.OrderBy(fmt.Sprintf("JSON_EXTRACT(footprint, \"$.%s\") ASC", field))
|
||||
query = query.OrderBy(fmt.Sprintf("json_extract(footprint, '$.%s') ASC", field))
|
||||
case model.SortDirectionEnumDesc:
|
||||
query = query.OrderBy(fmt.Sprintf("JSON_EXTRACT(footprint, \"$.%s\") DESC", field))
|
||||
query = query.OrderBy(fmt.Sprintf("json_extract(footprint, '$.%s') DESC", field))
|
||||
default:
|
||||
return nil, errors.New("invalid sorting order for footprint")
|
||||
}
|
||||
@@ -336,13 +335,12 @@ func buildTimeCondition(field string, cond *config.TimeRange, query sq.SelectBui
|
||||
|
||||
// buildFloatJSONCondition creates a filter on a numeric field within the footprint JSON column, using BETWEEN only if required.
|
||||
func buildFloatJSONCondition(field string, cond *model.FloatRange, query sq.SelectBuilder) sq.SelectBuilder {
|
||||
query = query.Where("JSON_VALID(footprint)")
|
||||
if cond.From != 1.0 && cond.To != 0.0 {
|
||||
return query.Where("JSON_EXTRACT(footprint, \"$."+field+"\") BETWEEN ? AND ?", cond.From, cond.To)
|
||||
return query.Where("json_extract(footprint, '$."+field+"') BETWEEN ? AND ?", cond.From, cond.To)
|
||||
} else if cond.From != 1.0 && cond.To == 0.0 {
|
||||
return query.Where("JSON_EXTRACT(footprint, \"$."+field+"\") >= ?", cond.From)
|
||||
return query.Where("json_extract(footprint, '$."+field+"') >= ?", cond.From)
|
||||
} else if cond.From == 1.0 && cond.To != 0.0 {
|
||||
return query.Where("JSON_EXTRACT(footprint, \"$."+field+"\") <= ?", cond.To)
|
||||
return query.Where("json_extract(footprint, '$."+field+"') <= ?", cond.To)
|
||||
} else {
|
||||
return query
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user