MM-32893: Refactor the getting of DB handle (#16943)
* MM-32893: Refactor the getting of DB handle We add a method in *SqlStore that returns the correct DB handle depending on the context. https://mattermost.atlassian.net/browse/MM-32893 ```release-note NONE ``` * fix receiver name
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
ee5668b834
Коммит
2596a9e630
@@ -5,6 +5,8 @@ package sqlstore
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/mattermost/gorp"
|
||||
)
|
||||
|
||||
// storeContextKey is the base type for all context keys for the store.
|
||||
@@ -32,3 +34,11 @@ func hasMaster(ctx context.Context) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// DBFromContext is a helper utility that returns the DB handle from a given context.
|
||||
func (ss *SqlStore) DBFromContext(ctx context.Context) *gorp.DbMap {
|
||||
if hasMaster(ctx) {
|
||||
return ss.GetMaster()
|
||||
}
|
||||
return ss.GetReplica()
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user