Skip to content

Commit

Permalink
FFM-9314 Check all flags to see if a single one is outdated
Browse files Browse the repository at this point in the history
**What**

- Changes conditon so we only break out of SetFlags if the flags ARE NOT
  outdated

**Why**

- If the flags are outdated we want to carry on inside SetFlags and
  refresh the cache
  • Loading branch information
jcox250 committed Sep 12, 2023
1 parent c029419 commit d73c1a9
Show file tree
Hide file tree
Showing 2 changed files with 341 additions and 24 deletions.
24 changes: 15 additions & 9 deletions pkg/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ func (r FFRepository) GetSegment(identifier string) (rest.Segment, error) {
// SetFlag places a flag in the repository with the new value
func (r FFRepository) SetFlag(featureConfig rest.FeatureConfig, initialLoad bool) {
if !initialLoad {
if r.isFlagOutdated(featureConfig) {
// If the flag is up to date then we don't need to bother updating the cache
if !r.isFlagOutdated(featureConfig) {
return
}
}
Expand All @@ -141,7 +142,8 @@ func (r FFRepository) SetFlag(featureConfig rest.FeatureConfig, initialLoad bool
// SetFlags places all the flags in the repository
func (r FFRepository) SetFlags(initialLoad bool, envID string, featureConfigs ...rest.FeatureConfig) {
if !initialLoad {
if r.areFlagsOutdated(featureConfigs...) {
// If the flags are all up to date then we don't need to bother updating the cache and can exit
if !r.areFlagsOutdated(featureConfigs...) {
return
}
}
Expand All @@ -165,7 +167,8 @@ func (r FFRepository) SetFlags(initialLoad bool, envID string, featureConfigs ..
// SetSegment places a segment in the repository with the new value
func (r FFRepository) SetSegment(segment rest.Segment, initialLoad bool) {
if !initialLoad {
if r.isSegmentOutdated(segment) {
// If the segment isn't outdated then we can exit as we don't need to refresh the cache
if !r.isSegmentOutdated(segment) {
return
}
}
Expand All @@ -187,7 +190,8 @@ func (r FFRepository) SetSegment(segment rest.Segment, initialLoad bool) {
// SetSegments places all the segments in the repository
func (r FFRepository) SetSegments(initialLoad bool, envID string, segments ...rest.Segment) {
if !initialLoad {
if r.areSegmentsOutdated(segments...) {
// If segments aren't outdated then we can exit as we don't need to refresh the cache
if !r.areSegmentsOutdated(segments...) {
return
}
}
Expand All @@ -204,7 +208,7 @@ func (r FFRepository) SetSegments(initialLoad bool, envID string, segments ...re
}

if r.callback != nil {
r.callback.OnFlagsStored(envID)
r.callback.OnSegmentsStored(envID)
}
}

Expand Down Expand Up @@ -243,10 +247,11 @@ func (r FFRepository) DeleteSegment(identifier string) {
func (r FFRepository) isFlagOutdated(featureConfig rest.FeatureConfig) bool {
oldFlag, err := r.getFlagAndCache(featureConfig.Feature, false)
if err != nil || oldFlag.Version == nil {
return false
// If we get an error here return true to force a cache update
return true
}

return *oldFlag.Version >= *featureConfig.Version
return *oldFlag.Version < *featureConfig.Version
}

func (r FFRepository) areFlagsOutdated(flags ...rest.FeatureConfig) bool {
Expand All @@ -261,10 +266,11 @@ func (r FFRepository) areFlagsOutdated(flags ...rest.FeatureConfig) bool {
func (r FFRepository) isSegmentOutdated(segment rest.Segment) bool {
oldSegment, err := r.getSegmentAndCache(segment.Identifier, false)
if err != nil || oldSegment.Version == nil {
return false
// If we get an error here return true to force a cache update
return true
}

return *oldSegment.Version >= *segment.Version
return *oldSegment.Version < *segment.Version
}

func (r FFRepository) areSegmentsOutdated(segments ...rest.Segment) bool {
Expand Down
Loading

0 comments on commit d73c1a9

Please sign in to comment.