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.
type BaseChannel struct {
Name string
Upstreams []UpstreamInfo
HTTPClient *http.Client
StreamClient *http.Client
TestModel string
upstreamLock sync.Mutex
Name string
Upstreams []UpstreamInfo
HTTPClient *http.Client
StreamClient *http.Client
TestModel string
upstreamLock sync.Mutex
// Cached fields from the group for stale check
channelType string
groupUpstreams datatypes.JSON
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.
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) {
return true
}
if !reflect.DeepEqual(b.effectiveConfig, &group.EffectiveConfig) {
return true
}
return false
}

View File

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