fix: Switch to channel-ratio

- Use channel ratios instead of group ratios in all applicable places
- Start using the lowest channel ratio of the specified channel's groups
This commit is contained in:
Laisky.Cai
2024-03-01 13:49:23 +00:00
parent ba827b95e3
commit dbe3930a8c
5 changed files with 24 additions and 8 deletions

View File

@@ -85,6 +85,16 @@ func Distribute() func(c *gin.Context) {
}
func SetupContextForSelectedChannel(c *gin.Context, channel *model.Channel, modelName string) {
// set minimal group ratio as channel_ratio
var minimalRatio float64
for _, grp := range strings.Split(channel.Group, ",") {
v := common.GetGroupRatio(grp)
if minimalRatio == 0 || v < minimalRatio {
minimalRatio = v
}
}
c.Set("channel_ratio", minimalRatio)
c.Set("channel", channel.Type)
c.Set("channel_id", channel.Id)
c.Set("channel_name", channel.Name)