fix(channel): improve proxy client compatibility and cache lifecycle (#6157)

* fix(channel): improve proxy client compatibility and cache lifecycle

* test(controller): use non-fatal assertions for channel tests
This commit is contained in:
yyhhyyyyyy
2026-07-20 18:11:22 +08:00
committed by GitHub
parent 08677566f8
commit e13d4033e5
26 changed files with 537 additions and 147 deletions
+16 -7
View File
@@ -452,26 +452,32 @@ func BatchInsertChannels(channels []Channel) error {
return tx.Commit().Error
}
func BatchDeleteChannels(ids []int) error {
func BatchDeleteChannels(ids []int) (int64, error) {
if len(ids) == 0 {
return nil
return 0, nil
}
// 使用事务 分批删除channel表和abilities表
tx := DB.Begin()
if tx.Error != nil {
return tx.Error
return 0, tx.Error
}
var deletedCount int64
for _, chunk := range lo.Chunk(ids, 200) {
if err := tx.Where("id in (?)", chunk).Delete(&Channel{}).Error; err != nil {
result := tx.Where("id in (?)", chunk).Delete(&Channel{})
if result.Error != nil {
tx.Rollback()
return err
return 0, result.Error
}
deletedCount += result.RowsAffected
if err := tx.Where("channel_id in (?)", chunk).Delete(&Ability{}).Error; err != nil {
tx.Rollback()
return err
return 0, err
}
}
return tx.Commit().Error
if err := tx.Commit().Error; err != nil {
return 0, err
}
return deletedCount, nil
}
func (channel *Channel) GetPriority() int64 {
@@ -945,6 +951,9 @@ func (channel *Channel) ValidateSettings() error {
return err
}
}
if _, err := common.ParseProxyURLStrict(channelParams.Proxy); err != nil {
return fmt.Errorf("invalid channel proxy: %w", err)
}
channelOtherSettings := &dto.ChannelOtherSettings{}
if channel.OtherSettings != "" {
err := common.UnmarshalJsonStr(channel.OtherSettings, channelOtherSettings)