Files
steampipe/steampipeconfig/connection_data.go
kaidaguerre 1fdfc02c34 Startup optimizations. Closes #1186. Closes #1183. Closes #1182
- Update connection management to use file modified time instead of filehash to detect connection changes
- Avoid retrieving schema from database for check and non-interactive query execution
- When retrieving plugin schema, identify the minimum set of schemas we need to fetch - to allow for multiple connections with the same schema
- Update plugin manager to instantiate plugins in parallel
2021-12-07 15:34:14 +00:00

51 lines
1.8 KiB
Go

package steampipeconfig
import (
"time"
"github.com/turbot/steampipe/steampipeconfig/modconfig"
)
// ConnectionDataStructVersion is used to force refreshing connections
// If we need to force a connection refresh (for example if any of the underlying schema generation code changes),
// updating this version will force all connections to refresh, as the deserialized data will have an old version
var ConnectionDataStructVersion int64 = 20211125
// ConnectionData is a struct containing all details for a connection
// - the plugin name and checksum, the connection config and options
// json tags needed as this is stored in the connection state file
type ConnectionData struct {
StructVersion int64
// the fully qualified name of the plugin
Plugin string
// the underlying connection object
Connection *modconfig.Connection
// schema mode - static or dynamic
SchemaMode string `json:"SchemaMode,omitempty"`
// the hash of the connection schema
SchemaHash string `json:"SchemaHash,omitempty"`
// the creation time of the plugin file (only used for local plugins)
ModTime time.Time
}
func NewConnectionData(remoteSchema string, connection *modconfig.Connection, creationTime time.Time) *ConnectionData {
return &ConnectionData{
StructVersion: ConnectionDataStructVersion,
Plugin: remoteSchema,
Connection: connection,
ModTime: creationTime,
}
}
func (p *ConnectionData) Equals(other *ConnectionData) bool {
if p.Connection == nil || other.Connection == nil {
// if either object has a nil Connection, then it may be data from an old connection state file
// return false, so that connections get refreshed and this file gets written in the new format in the process
return false
}
return p.Plugin == other.Plugin &&
p.ModTime.Equal(other.ModTime) &&
p.Connection.Equals(other.Connection)
}