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:
Artur Wierzbicki 2022-10-25 09:39:17 +08:00 committed by GitHub
parent 749b3b6263
commit e485ddd13d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 13 deletions

View File

@ -59,7 +59,7 @@ func exportDashboards(helper *commitHelper, job *gitExportJob) error {
return err
}
reader := dashboard.NewStaticDashboardSummaryBuilder(lookup)
reader := dashboard.NewStaticDashboardSummaryBuilder(lookup, false)
// Process all folders
for _, row := range rows {

View File

@ -953,7 +953,7 @@ func (l sqlDashboardLoader) LoadDashboards(ctx context.Context, orgID int64, das
readDashboardSpan.SetAttributes("orgID", orgID, attribute.Key("orgID").Int64(orgID))
readDashboardSpan.SetAttributes("dashboardCount", len(rows), attribute.Key("dashboardCount").Int(len(rows)))
reader := kdash.NewStaticDashboardSummaryBuilder(lookup)
reader := kdash.NewStaticDashboardSummaryBuilder(lookup, false)
for _, row := range rows {
summary, _, err := reader(ctx, row.Uid, row.Data)

View File

@ -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
}
}