mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
SQL Engine: Handle one session to connect the DB (#63246)
fix(postgresql): Handle one session to the DB
This commit is contained in:
parent
5fdf1f4862
commit
fa0f640d6a
@ -97,7 +97,9 @@ type DataSourceHandler struct {
|
||||
log log.Logger
|
||||
dsInfo DataSourceInfo
|
||||
rowLimit int64
|
||||
session *xorm.Session
|
||||
}
|
||||
|
||||
type QueryJson struct {
|
||||
RawSql string `json:"rawSql"`
|
||||
Fill bool `json:"fill"`
|
||||
@ -145,6 +147,7 @@ func NewQueryDataHandler(config DataPluginConfiguration, queryResultTransformer
|
||||
queryDataHandler.metricColumnTypes = config.MetricColumnTypes
|
||||
}
|
||||
|
||||
// Create the xorm engine
|
||||
engine, err := NewXormEngine(config.DriverName, config.ConnectionString)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -155,6 +158,11 @@ func NewQueryDataHandler(config DataPluginConfiguration, queryResultTransformer
|
||||
engine.SetConnMaxLifetime(time.Duration(config.DSInfo.JsonData.ConnMaxLifetime) * time.Second)
|
||||
|
||||
queryDataHandler.engine = engine
|
||||
|
||||
// Create the xorm session
|
||||
session := engine.NewSession()
|
||||
queryDataHandler.session = session
|
||||
|
||||
return &queryDataHandler, nil
|
||||
}
|
||||
|
||||
@ -265,9 +273,7 @@ func (e *DataSourceHandler) executeQuery(query backend.DataQuery, wg *sync.WaitG
|
||||
return
|
||||
}
|
||||
|
||||
session := e.engine.NewSession()
|
||||
defer session.Close()
|
||||
db := session.DB()
|
||||
db := e.session.DB()
|
||||
|
||||
rows, err := db.QueryContext(queryContext, interpolatedQuery)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user