Skip to content

Commit

Permalink
Merge branch 'feature/conflict_key_priority' into feature/support_domain
Browse files Browse the repository at this point in the history
  • Loading branch information
oMinGWo committed Nov 4, 2024
2 parents b33361b + 91b9a4d commit 6241ba6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
16 changes: 13 additions & 3 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/volcengine/datatester-go-sdk/handler"
"github.com/volcengine/datatester-go-sdk/log"
"github.com/volcengine/datatester-go-sdk/meta/manager"
"github.com/volcengine/datatester-go-sdk/utils"
)

type AbClient struct {
Expand Down Expand Up @@ -180,7 +181,10 @@ func (t *AbClient) GetAllExperimentConfigs(decisionId string,
continue
}
for k, v := range confMap {
configs[k] = v
existConfig, conflict := configs[k]
if !conflict || utils.IsHigherPriorityConfig(existConfig, v) {
configs[k] = v
}
}
}
t.updateUserAbInfo(decisionId, experiment2variant)
Expand Down Expand Up @@ -212,7 +216,10 @@ func (t *AbClient) getAllExperimentConfigs4Activate(variantKey, decisionId strin
continue
}
for k, v := range confMap {
configs[k] = v
existConfig, conflict := configs[k]
if !conflict || utils.IsHigherPriorityConfig(existConfig, v) {
configs[k] = v
}
}
vid2ExperimentIdMap[variant.Id] = variant.ExperimentId
}
Expand Down Expand Up @@ -426,7 +433,10 @@ func (t *AbClient) GetAllFeatureConfigs(decisionId string,
continue
}
for k, v := range confMap {
configs[k] = v
existConfig, conflict := configs[k]
if !conflict || utils.IsHigherPriorityConfig(existConfig, v) {
configs[k] = v
}
}
}
return configs, nil
Expand Down
18 changes: 18 additions & 0 deletions utils/conflict.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package utils

import (
"strconv"
"strings"
)

func IsHigherPriorityConfig(existConf, newConf map[string]interface{}) bool {
vid1 := existConf["vid"].(string)
vid2 := newConf["vid"].(string)
v1, err1 := strconv.ParseInt(vid1, 10, 64)
v2, err2 := strconv.ParseInt(vid2, 10, 64)
// 转换失败,则按照字符串对比,一般不会出现
if err1 != nil || err2 != nil {
return strings.Compare(vid2, vid1) < 0
}
return v2 < v1
}

0 comments on commit 6241ba6

Please sign in to comment.