fix: 当totalWeight小于等于0时随机选择渠道 - #2126
Conversation
WalkthroughReplace the previous zero-weight guard with a deterministic fallback: if computed Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant ChannelCache
participant RNG as rand.Intn
Caller->>ChannelCache: request SelectChannel(targetChannels)
ChannelCache->>ChannelCache: compute totalWeight (after smoothing)
alt totalWeight > 0
ChannelCache->>RNG: n = rand.Intn(totalWeight)
ChannelCache->>ChannelCache: iterate channels, subtract weights until n < 0
ChannelCache->>Caller: return selected channel
else totalWeight <= 0
alt targetChannels not empty
ChannelCache->>ChannelCache: totalWeight = len(targetChannels) * 100
ChannelCache->>RNG: n = rand.Intn(totalWeight)
ChannelCache->>ChannelCache: iterate channels, subtract 100 per channel until n < 0
ChannelCache->>Caller: return selected channel
else no channels
ChannelCache->>Caller: return error "no available channels"
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…-panic fix: 当totalWeight小于等于0时设置为1选择第一个渠道
fix #2125
Summary by CodeRabbit