refactor(group): update user group handling to utilize userUsableGroups directly and add GetUserGroupRatio function
This commit is contained in:
@@ -29,11 +29,11 @@ func GetUserGroups(c *gin.Context) {
|
|||||||
userId := c.GetInt("id")
|
userId := c.GetInt("id")
|
||||||
userGroup, _ = model.GetUserGroup(userId, false)
|
userGroup, _ = model.GetUserGroup(userId, false)
|
||||||
userUsableGroups := service.GetUserUsableGroups(userGroup)
|
userUsableGroups := service.GetUserUsableGroups(userGroup)
|
||||||
for groupName, ratio := range ratio_setting.GetGroupRatioCopy() {
|
for groupName, _ := range ratio_setting.GetGroupRatioCopy() {
|
||||||
// UserUsableGroups contains the groups that the user can use
|
// UserUsableGroups contains the groups that the user can use
|
||||||
if desc, ok := userUsableGroups[groupName]; ok {
|
if desc, ok := userUsableGroups[groupName]; ok {
|
||||||
usableGroups[groupName] = map[string]interface{}{
|
usableGroups[groupName] = map[string]interface{}{
|
||||||
"ratio": ratio,
|
"ratio": service.GetUserGroupRatio(userGroup, groupName),
|
||||||
"desc": desc,
|
"desc": desc,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ func Playground(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
group := c.GetString("group")
|
group := common.GetContextKeyString(c, constant.ContextKeyUsingGroup)
|
||||||
modelName := c.GetString("original_model")
|
modelName := c.GetString("original_model")
|
||||||
|
|
||||||
userId := c.GetInt("id")
|
userId := c.GetInt("id")
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ func Distribute() func(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
usingGroup = playgroundRequest.Group
|
usingGroup = playgroundRequest.Group
|
||||||
|
common.SetContextKey(c, constant.ContextKeyUsingGroup, usingGroup)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
channel, selectGroup, err = service.CacheGetRandomSatisfiedChannel(c, usingGroup, modelRequest.Model, 0)
|
channel, selectGroup, err = service.CacheGetRandomSatisfiedChannel(c, usingGroup, modelRequest.Model, 0)
|
||||||
|
|||||||
@@ -52,3 +52,14 @@ func GetUserAutoGroup(userGroup string) []string {
|
|||||||
}
|
}
|
||||||
return autoGroups
|
return autoGroups
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetUserGroupRatio 获取用户使用某个分组的倍率
|
||||||
|
// userGroup 用户分组
|
||||||
|
// group 需要获取倍率的分组
|
||||||
|
func GetUserGroupRatio(userGroup, group string) float64 {
|
||||||
|
ratio, ok := ratio_setting.GetGroupGroupRatio(userGroup, group)
|
||||||
|
if ok {
|
||||||
|
return ratio
|
||||||
|
}
|
||||||
|
return ratio_setting.GetGroupRatio(group)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user