Skip to content

Commit

Permalink
fetching flag metadata with a single lock
Browse files Browse the repository at this point in the history
Signed-off-by: Aasif Khan <aasifk106@gmail.com>
  • Loading branch information
aasifkhan7 committed Dec 20, 2024
1 parent dd48ee3 commit 5cb824c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
17 changes: 8 additions & 9 deletions core/pkg/evaluator/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,18 +331,17 @@ func (je *Resolver) evaluateVariant(ctx context.Context, reqID string, flagKey s
metadata[SelectorMetadataKey] = selector
}

flagMetadata := je.store.MetadataForFlag(ctx, flag)
if flagMetadata.ID != "" {
metadata[ID] = flagMetadata.ID
if flag.Metadata.ID != "" {
metadata[ID] = flag.Metadata.ID
}
if flagMetadata.Version != "" {
metadata[VERSION] = flagMetadata.Version
if flag.Metadata.Version != "" {
metadata[VERSION] = flag.Metadata.Version
}
if flagMetadata.FlagSetID != "" {
metadata[FLAGSETID] = flagMetadata.FlagSetID
if flag.Metadata.FlagSetID != "" {
metadata[FLAGSETID] = flag.Metadata.FlagSetID
}
if flagMetadata.FlagSetVersion != "" {
metadata[FLAGSETVERSION] = flagMetadata.FlagSetVersion
if flag.Metadata.FlagSetVersion != "" {
metadata[FLAGSETVERSION] = flag.Metadata.FlagSetVersion
}

if flag.State == Disabled {
Expand Down
8 changes: 0 additions & 8 deletions core/pkg/store/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ type IStore interface {
GetAll(ctx context.Context) (map[string]model.Flag, error)
Get(ctx context.Context, key string) (model.Flag, bool)
SelectorForFlag(ctx context.Context, flag model.Flag) string
MetadataForFlag(ctx context.Context, flag model.Flag) model.Metadata
}

type Flags struct {
Expand Down Expand Up @@ -74,13 +73,6 @@ func (f *Flags) SelectorForFlag(_ context.Context, flag model.Flag) string {
return f.SourceMetadata[flag.Source].Selector
}

func (f *Flags) MetadataForFlag(_ context.Context, flag model.Flag) model.Metadata {
f.mx.RLock()
defer f.mx.RUnlock()

return flag.Metadata
}

func (f *Flags) Delete(key string) {
f.mx.Lock()
defer f.mx.Unlock()
Expand Down

0 comments on commit 5cb824c

Please sign in to comment.