Commit e6333e93 by t0ng7u

🐛 fix: synchronize `MultiKeySize` after editing multi-key channels

1. Recalculate `ChannelInfo.MultiKeySize` based on the current key list when a multi-key channel is updated.
2. Purge any indexes in `MultiKeyStatusList` that exceed the new key count to avoid stale or out-of-range data.

This ensures the front-end display (`enabled x/x`) always reflects the real number of keys after users add or remove keys in edit mode.
parent a66430c8
......@@ -396,6 +396,19 @@ func (channel *Channel) Insert() error {
}
func (channel *Channel) Update() error {
// 如果是多密钥渠道,则根据当前 key 列表重新计算 MultiKeySize,避免编辑密钥后数量未同步
if channel.ChannelInfo.IsMultiKey {
keys := channel.getKeys()
channel.ChannelInfo.MultiKeySize = len(keys)
// 清理超过新 key 数量范围的状态数据,防止索引越界
if channel.ChannelInfo.MultiKeyStatusList != nil {
for idx := range channel.ChannelInfo.MultiKeyStatusList {
if idx >= channel.ChannelInfo.MultiKeySize {
delete(channel.ChannelInfo.MultiKeyStatusList, idx)
}
}
}
}
var err error
err = DB.Model(channel).Updates(channel).Error
if err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment