Migrate emojiStore to use request.CTX instead of context.Context (#24514)
* migrate emojistore to request.ctx * use mlog.CreateConsoleTestLogger * Add comment to WithMaster and RequestContextWithMaster
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
e9cc03c1c8
Коммит
f65dad83bb
@@ -5,6 +5,8 @@ package sqlstore
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
)
|
||||
|
||||
// storeContextKey is the base type for all context keys for the store.
|
||||
@@ -19,10 +21,20 @@ const (
|
||||
)
|
||||
|
||||
// WithMaster adds the context value that master DB should be selected for this request.
|
||||
//
|
||||
// Deprecated: This method is deprecated and there's ongoing change to use `request.CTX` across
|
||||
// instead of `context.Context`. Please use `RequestContextWithMaster` instead.
|
||||
func WithMaster(ctx context.Context) context.Context {
|
||||
return context.WithValue(ctx, storeContextKey(useMaster), true)
|
||||
}
|
||||
|
||||
// RequestContextWithMaster adds the context value that master DB should be selected for this request.
|
||||
func RequestContextWithMaster(c request.CTX) request.CTX {
|
||||
ctx := WithMaster(c.Context())
|
||||
c.SetContext(ctx)
|
||||
return c
|
||||
}
|
||||
|
||||
// hasMaster is a helper function to check whether master DB should be selected or not.
|
||||
func hasMaster(ctx context.Context) bool {
|
||||
if v := ctx.Value(storeContextKey(useMaster)); v != nil {
|
||||
|
||||
Ссылка в новой задаче
Block a user