Files
steampipe/pkg/utils/map.go
kaidaguerre 40804a3201 Execute RefreshConnections asyncronously and optimise for high connection count. Add connection_state table.
- Execute RefreshConnections asyncronously
- Add connection_state table to indicate the loading state of connections
- Optimise RefreshConnections by cloning connection schemas
- Add locking to ensure only a single instance of RefreshConnections runs
- Start executing queries without waiting for connections to load, add smart error handling to wait for required connection
- Optimise autocomplete for high connection count
- Autocomplete and inspect data available before all conections are refreshed
- Update file watcher to respond to CHMOD, so thaat it pickes up deletion of file contents

 Closes #3394
 Closes #3267
2023-05-10 09:05:08 +01:00

43 lines
739 B
Go

package utils
import (
"sort"
"golang.org/x/exp/maps"
)
// MergeMaps merges 'new' onto 'old'.
// Values existing in old already have precedence
// Any value existing in new but not old is added to old
func MergeMaps[M ~map[K]V, K comparable, V any](old, new M) M {
if old == nil {
return new
}
if new == nil {
return old
}
res := maps.Clone(old)
for k, v := range new {
if _, ok := old[k]; !ok {
res[k] = v
}
}
return res
}
func SortedMapKeys[V any](m map[string]V) []string {
var keys = maps.Keys(m)
sort.Strings(keys)
return keys
}
func SliceToLookup[K comparable](src []K) map[K]struct{} {
var result = make(map[K]struct{}, len(src))
for _, k := range src {
result[k] = struct{}{}
}
return result
}