Skip to content

Commit

Permalink
remove redundant mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
verygoodsoftwarenotvirus committed Sep 6, 2023
1 parent 9679b55 commit 41f6c8a
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions featureflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ type FeatureFlagsPoller struct {
loaded chan bool
shutdown chan bool
forceReload chan bool
featureFlagsHat sync.Mutex
featureFlags []FeatureFlag
groups map[string]string
personalApiKey string
Expand Down Expand Up @@ -178,13 +177,11 @@ func (poller *FeatureFlagsPoller) fetchNewFeatureFlags() {
}

poller.mutex.Lock()
poller.featureFlagsHat.Lock()
poller.featureFlags = newFlags
if featureFlagsResponse.GroupTypeMapping != nil {
poller.groups = *featureFlagsResponse.GroupTypeMapping
}
poller.fetchedFlagsSuccessfullyOnce = true
poller.featureFlagsHat.Unlock()
poller.mutex.Unlock()
}

Expand Down Expand Up @@ -267,7 +264,9 @@ func (poller *FeatureFlagsPoller) computeFlagLocally(flag FeatureFlag, distinctI
}

if flag.Filters.AggregationGroupTypeIndex != nil {
poller.mutex.RLock()
groupName, exists := poller.groups[fmt.Sprintf("%d", *flag.Filters.AggregationGroupTypeIndex)]
poller.mutex.RUnlock()

if !exists {
errMessage := "Flag has unknown group type index"
Expand Down Expand Up @@ -634,8 +633,8 @@ func (poller *FeatureFlagsPoller) GetFeatureFlags() []FeatureFlag {
<-poller.loaded
}

poller.featureFlagsHat.Lock()
defer poller.featureFlagsHat.Unlock()
poller.mutex.Lock()
defer poller.mutex.Unlock()
return poller.featureFlags
}

Expand Down

0 comments on commit 41f6c8a

Please sign in to comment.