mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Store: don't marshall/unmarshall the dashboard when building a summary (#57520)
* dont pretty print the dashboard * stop marshalling the dashboard * do not sanitize for searchV2 Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
This commit is contained in:
@@ -21,24 +21,27 @@ func GetObjectKindInfo() models.ObjectKindInfo {
|
||||
|
||||
// This summary does not resolve old name as UID
|
||||
func GetObjectSummaryBuilder() models.ObjectSummaryBuilder {
|
||||
builder := NewStaticDashboardSummaryBuilder(&directLookup{})
|
||||
builder := NewStaticDashboardSummaryBuilder(&directLookup{}, true)
|
||||
return func(ctx context.Context, uid string, body []byte) (*models.ObjectSummary, []byte, error) {
|
||||
return builder(ctx, uid, body)
|
||||
}
|
||||
}
|
||||
|
||||
// This implementation moves datasources referenced by internal ID or name to UID
|
||||
func NewStaticDashboardSummaryBuilder(lookup DatasourceLookup) models.ObjectSummaryBuilder {
|
||||
func NewStaticDashboardSummaryBuilder(lookup DatasourceLookup, sanitize bool) models.ObjectSummaryBuilder {
|
||||
return func(ctx context.Context, uid string, body []byte) (*models.ObjectSummary, []byte, error) {
|
||||
var parsed map[string]interface{}
|
||||
err := json.Unmarshal(body, &parsed)
|
||||
if err != nil {
|
||||
return nil, nil, err // did not parse
|
||||
|
||||
if sanitize {
|
||||
err := json.Unmarshal(body, &parsed)
|
||||
if err != nil {
|
||||
return nil, nil, err // did not parse
|
||||
}
|
||||
// values that should be managed by the container
|
||||
delete(parsed, "uid")
|
||||
delete(parsed, "version")
|
||||
// slug? (derived from title)
|
||||
}
|
||||
// values that should be managed by the container
|
||||
delete(parsed, "uid")
|
||||
delete(parsed, "version")
|
||||
// slug? (derived from title)
|
||||
|
||||
summary := &models.ObjectSummary{
|
||||
Labels: make(map[string]string),
|
||||
@@ -98,7 +101,9 @@ func NewStaticDashboardSummaryBuilder(lookup DatasourceLookup) models.ObjectSumm
|
||||
}
|
||||
|
||||
summary.References = dashboardRefs.Get()
|
||||
out, err := json.MarshalIndent(parsed, "", " ")
|
||||
return summary, out, err
|
||||
if sanitize {
|
||||
body, err = json.MarshalIndent(parsed, "", " ")
|
||||
}
|
||||
return summary, body, err
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user