diff --git a/CHANGELOG.md b/CHANGELOG.md index b467b2553..4653d065b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ _What's new?_ * Add `Variables` and `Inputs` to dashboard `ExecutionStarted` event. ([#2606](https://github.com/turbot/steampipe/issues/2606)) * Validate check output and export formats _before_ execution. ([#2619](https://github.com/turbot/steampipe/issues/2619)) * When starting a plugin process, pass a SecureConfig, to silence the `nil SecureConfig` error. ([#2567](https://github.com/turbot/steampipe/issues/2567)) +* Optimise autocomplete by only loading completions on startup or when connection config changes, rather than every time a query is entered . ([#2561](https://github.com/turbot/steampipe/issues/2561)) _Bug fixes_ * Update `GetPathKeys` to treat key columns with `AnyOf` require property with the same precedence as `Required`. ([#254](https://github.com/turbot/steampipe-postgres-fdw/issues/254)) diff --git a/pkg/cloud/snapshot.go b/pkg/cloud/snapshot.go index 67e0e56a2..2125f1b4c 100644 --- a/pkg/cloud/snapshot.go +++ b/pkg/cloud/snapshot.go @@ -90,7 +90,7 @@ func uploadSnapshot(ctx context.Context, snapshot *dashboardtypes.SteampipeSnaps } // strip verbose/sensitive fields - stripSnapshotForUpload(cloudSnapshot) + dashboardtypes.StripSnapshot(cloudSnapshot) req := steampipecloud.CreateWorkspaceSnapshotRequest{Data: *cloudSnapshot, Tags: tags, Visibility: &visibility} req.SetTitle(title) @@ -116,28 +116,6 @@ func uploadSnapshot(ctx context.Context, snapshot *dashboardtypes.SteampipeSnaps return snapshotUrl, nil } -func stripSnapshotForUpload(snapshot *steampipecloud.WorkspaceSnapshotData) { - propertiesToStrip := []string{ - "sql", - "source_definition", - "documentation", - "search_path", - "search_path_prefix"} - for _, p := range snapshot.Panels { - panel := p.(map[string]any) - properties, _ := panel["properties"].(map[string]any) - for _, property := range propertiesToStrip { - // look both at top level and under properties - delete(panel, property) - if properties != nil { - delete(properties, property) - } - } - } - // clear top level search path - snapshot.SearchPath = []string{} -} - func resolveSnapshotTitle(snapshot *dashboardtypes.SteampipeSnapshot) string { if titleArg := viper.GetString(constants.ArgSnapshotTitle); titleArg != "" { return titleArg diff --git a/pkg/dashboard/dashboardtypes/snapshot.go b/pkg/dashboard/dashboardtypes/snapshot.go index a25f7947c..ceff09bd8 100644 --- a/pkg/dashboard/dashboardtypes/snapshot.go +++ b/pkg/dashboard/dashboardtypes/snapshot.go @@ -37,3 +37,40 @@ func (s *SteampipeSnapshot) AsCloudSnapshot() (*steampipecloud.WorkspaceSnapshot return res, nil } + +func (s *SteampipeSnapshot) AsStrippedJson(indent bool) ([]byte, error) { + res, err := s.AsCloudSnapshot() + if err != nil { + return nil, err + } + if err = StripSnapshot(res); err != nil { + return nil, err + } + if indent { + return json.MarshalIndent(res, "", " ") + } + return json.Marshal(res) +} + +func StripSnapshot(snapshot *steampipecloud.WorkspaceSnapshotData) error { + propertiesToStrip := []string{ + "sql", + "source_definition", + "documentation", + "search_path", + "search_path_prefix"} + for _, p := range snapshot.Panels { + panel := p.(map[string]any) + properties, _ := panel["properties"].(map[string]any) + for _, property := range propertiesToStrip { + // look both at top level and under properties + delete(panel, property) + if properties != nil { + delete(properties, property) + } + } + } + // clear top level search path + snapshot.SearchPath = []string{} + return nil +} diff --git a/pkg/export/snapshot_exporter.go b/pkg/export/snapshot_exporter.go index 0939b74bc..6fdafe65c 100644 --- a/pkg/export/snapshot_exporter.go +++ b/pkg/export/snapshot_exporter.go @@ -2,7 +2,6 @@ package export import ( "context" - "encoding/json" "fmt" "github.com/turbot/steampipe/pkg/constants" "github.com/turbot/steampipe/pkg/dashboard/dashboardtypes" @@ -15,16 +14,15 @@ type SnapshotExporter struct { func (e *SnapshotExporter) Export(_ context.Context, input ExportSourceData, filePath string) error { snapshot, ok := input.(*dashboardtypes.SteampipeSnapshot) - if !ok { return fmt.Errorf("SnapshotExporter inp-ut must be *dashboardtypes.SteampipeSnapshot") } - snapshotStr, err := json.MarshalIndent(snapshot, "", " ") + snapshotBytes, err := snapshot.AsStrippedJson(false) if err != nil { return err } - res := strings.NewReader(fmt.Sprintf("%s\n", string(snapshotStr))) + res := strings.NewReader(fmt.Sprintf("%s\n", string(snapshotBytes))) return Write(filePath, res) }