Skip to content

Commit

Permalink
Remove the nsContext cache (#5200)
Browse files Browse the repository at this point in the history
  • Loading branch information
briankassouf committed Aug 27, 2018
1 parent e5aaf80 commit 79ec8e0
Showing 1 changed file with 1 addition and 23 deletions.
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

0 comments on commit 79ec8e0

Please sign in to comment.