feat: 优化渠道分组配置更新机制

This commit is contained in:
tbphp
2025-07-13 12:32:09 +08:00
parent 53700b5728
commit 399fb1bcb3
2 changed files with 16 additions and 8 deletions

View File

@@ -23,12 +23,15 @@ type UpstreamInfo struct {
// BaseChannel provides common functionality for channel proxies. // BaseChannel provides common functionality for channel proxies.
type BaseChannel struct { type BaseChannel struct {
Name string Name string
Upstreams []UpstreamInfo Upstreams []UpstreamInfo
HTTPClient *http.Client HTTPClient *http.Client
StreamClient *http.Client StreamClient *http.Client
TestModel string TestModel string
upstreamLock sync.Mutex upstreamLock sync.Mutex
// Cached fields from the group for stale check
channelType string
groupUpstreams datatypes.JSON groupUpstreams datatypes.JSON
effectiveConfig *types.SystemSettings effectiveConfig *types.SystemSettings
} }
@@ -87,14 +90,18 @@ func (b *BaseChannel) BuildUpstreamURL(originalURL *url.URL, group *models.Group
// IsConfigStale checks if the channel's configuration is stale compared to the provided group. // IsConfigStale checks if the channel's configuration is stale compared to the provided group.
func (b *BaseChannel) IsConfigStale(group *models.Group) bool { func (b *BaseChannel) IsConfigStale(group *models.Group) bool {
if b.channelType != group.ChannelType {
return true
}
if b.TestModel != group.TestModel {
return true
}
if !bytes.Equal(b.groupUpstreams, group.Upstreams) { if !bytes.Equal(b.groupUpstreams, group.Upstreams) {
return true return true
} }
if !reflect.DeepEqual(b.effectiveConfig, &group.EffectiveConfig) { if !reflect.DeepEqual(b.effectiveConfig, &group.EffectiveConfig) {
return true return true
} }
return false return false
} }

View File

@@ -145,6 +145,7 @@ func (f *Factory) newBaseChannel(name string, group *models.Group) (*BaseChannel
HTTPClient: httpClient, HTTPClient: httpClient,
StreamClient: streamClient, StreamClient: streamClient,
TestModel: group.TestModel, TestModel: group.TestModel,
channelType: group.ChannelType,
groupUpstreams: group.Upstreams, groupUpstreams: group.Upstreams,
effectiveConfig: &group.EffectiveConfig, effectiveConfig: &group.EffectiveConfig,
}, nil }, nil