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

Bugfix: Cater to optional segmenter matches in filterByLookupOrder #35

Merged
merged 2 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 10 additions & 11 deletions treatment-service/services/experiment_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,38 +128,37 @@ func (es *experimentService) filterByLookupOrder(
filtered := matches
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if the above // Stop search when we have at least 1 match is still relevant here. Feels like it should be shifted down 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed this comment - not sure it had much significance previously either. Removed it. Thanks for pointing out.

for _, segmenter := range segmenters {
orderedValues := filters[segmenter]
if len(orderedValues) == 1 {
continue
}

currentFilteredList := []*models.ExperimentMatch{}
segmenterType := segmenterTypes[segmenter]
for _, transformedValue := range orderedValues {
if len(currentFilteredList) == 0 {
for _, segmenterMatch := range filtered {
segmenterMatchedValue := segmenterMatch.SegmenterMatches[segmenter]
for _, experiment := range filtered {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for renaming this 👍🏻 , segmenterMatch really didn't make any sense as I was reviewing these changes.

segmenterMatchedValue := experiment.SegmenterMatches[segmenter]
switch segmenterType {
case "string":
if transformedValue.GetString_() == segmenterMatchedValue.Value.GetString_() {
currentFilteredList = append(currentFilteredList, segmenterMatch)
currentFilteredList = append(currentFilteredList, experiment)
}
case "integer":
if transformedValue.GetInteger() == segmenterMatchedValue.Value.GetInteger() {
currentFilteredList = append(currentFilteredList, segmenterMatch)
currentFilteredList = append(currentFilteredList, experiment)
}
case "real":
if transformedValue.GetReal() == segmenterMatchedValue.Value.GetReal() {
currentFilteredList = append(currentFilteredList, segmenterMatch)
currentFilteredList = append(currentFilteredList, experiment)
}
case "bool":
if transformedValue.GetBool() == segmenterMatchedValue.Value.GetBool() {
currentFilteredList = append(currentFilteredList, segmenterMatch)
currentFilteredList = append(currentFilteredList, experiment)
}
}
}
}
}
filtered = currentFilteredList
// currentFilteredList could be 0 in case of weak matches
if len(currentFilteredList) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to affirm my understanding, this is because orderedValues could potentially be empty right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. Added more info in the comment now.

filtered = currentFilteredList
}
}

return filtered
Expand Down
6 changes: 6 additions & 0 deletions treatment-service/services/experiment_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,12 @@ func (s *ExperimentServiceTestSuite) TestGetExperiment() {
expLookupFilters: makeExperimentLookupFilters(s2.CellID(3592210809859604480), 1, 20, "seg-1", 1, 9001, false),
expResponse: s.LocalStorage.Experiments[5][0].Experiment,
},
"resolve tiers | no experiment variables": {
projectId: 5,
reqFilter: map[string][]*_segmenters.SegmenterValue{},
expLookupFilters: makeExperimentLookupFilters(s2.CellID(3592210809859604480), 1, 20, "seg-1", 1, 9001, false),
expResponse: s.LocalStorage.Experiments[5][0].Experiment,
},
"resolve all hierarchy | optional segmenter": {
projectId: 6,
reqFilter: makeRequestFilter(s2.CellID(3592210809859604480), 1, 20, "seg-1", 1, 9001, false),
Expand Down