Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the nsContext cache #5200

Merged
merged 1 commit into from
Aug 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 1 addition & 23 deletions helper/namespace/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@ import (
"strings"
)

type nsContext struct {
context.Context
// Note: this is currently not locked because we think all uses will take
// place within a single goroutine. If that isn't the case, this should be
// protected by an atomic.Value.
cachedNS *Namespace
}

type contextValues struct{}

type Namespace struct {
Expand Down Expand Up @@ -55,11 +47,7 @@ func (n *Namespace) TrimmedPath(path string) string {
}

func ContextWithNamespace(ctx context.Context, ns *Namespace) context.Context {
nsCtx := context.WithValue(ctx, contextNamespace, ns)
return &nsContext{
Context: nsCtx,
cachedNS: ns,
}
return context.WithValue(ctx, contextNamespace, ns)
}

func RootContext(ctx context.Context) context.Context {
Expand All @@ -79,13 +67,6 @@ func FromContext(ctx context.Context) (*Namespace, error) {
return nil, errors.New("context was nil")
}

nsCtx, ok := ctx.(*nsContext)
if ok {
if nsCtx.cachedNS != nil {
return nsCtx.cachedNS, nil
}
}

nsRaw := ctx.Value(contextNamespace)
if nsRaw == nil {
return nil, ErrNoNamespace
Expand All @@ -96,9 +77,6 @@ func FromContext(ctx context.Context) (*Namespace, error) {
return nil, ErrNoNamespace
}

if ok {
nsCtx.cachedNS = ns
}
return ns, nil
}

Expand Down