mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 13:00:52 +08:00
fix(access): Force rebuild of aliased provider configurations
The provider reconciliation logic did not correctly handle aliased provider configurations (e.g., using YAML anchors). When a provider config was aliased, the check for configuration equality would pass, causing the system to reuse the existing provider instance without rebuilding it, even if the underlying configuration had changed. This change introduces a check to detect if the old and new provider configurations point to the same object in memory. If they are aliased, the provider is now always rebuilt to ensure it reflects the latest configuration. The optimization to reuse an existing provider based on deep equality is now only applied to non-aliased providers.
This commit is contained in:
@@ -37,11 +37,14 @@ func ReconcileProviders(oldCfg, newCfg *config.Config, existing []Provider) (res
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if oldCfgProvider, ok := oldCfgMap[key]; ok && providerConfigEqual(oldCfgProvider, providerCfg) {
|
if oldCfgProvider, ok := oldCfgMap[key]; ok {
|
||||||
if existingProvider, ok := existingMap[key]; ok {
|
isAliased := oldCfgProvider == providerCfg
|
||||||
result = append(result, existingProvider)
|
if !isAliased && providerConfigEqual(oldCfgProvider, providerCfg) {
|
||||||
finalIDs[key] = struct{}{}
|
if existingProvider, okExisting := existingMap[key]; okExisting {
|
||||||
continue
|
result = append(result, existingProvider)
|
||||||
|
finalIDs[key] = struct{}{}
|
||||||
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,9 +70,23 @@ func ReconcileProviders(oldCfg, newCfg *config.Config, existing []Provider) (res
|
|||||||
if providerCfg := newCfg.ConfigAPIKeyProvider(); providerCfg != nil {
|
if providerCfg := newCfg.ConfigAPIKeyProvider(); providerCfg != nil {
|
||||||
key := providerIdentifier(providerCfg)
|
key := providerIdentifier(providerCfg)
|
||||||
if key != "" {
|
if key != "" {
|
||||||
if oldCfgProvider, ok := oldCfgMap[key]; ok && providerConfigEqual(oldCfgProvider, providerCfg) {
|
if oldCfgProvider, ok := oldCfgMap[key]; ok {
|
||||||
if existingProvider, ok := existingMap[key]; ok {
|
isAliased := oldCfgProvider == providerCfg
|
||||||
result = append(result, existingProvider)
|
if !isAliased && providerConfigEqual(oldCfgProvider, providerCfg) {
|
||||||
|
if existingProvider, okExisting := existingMap[key]; okExisting {
|
||||||
|
result = append(result, existingProvider)
|
||||||
|
} else {
|
||||||
|
provider, buildErr := buildProvider(providerCfg, newCfg)
|
||||||
|
if buildErr != nil {
|
||||||
|
return nil, nil, nil, nil, buildErr
|
||||||
|
}
|
||||||
|
if _, existed := existingMap[key]; existed {
|
||||||
|
updated = append(updated, key)
|
||||||
|
} else {
|
||||||
|
added = append(added, key)
|
||||||
|
}
|
||||||
|
result = append(result, provider)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
provider, buildErr := buildProvider(providerCfg, newCfg)
|
provider, buildErr := buildProvider(providerCfg, newCfg)
|
||||||
if buildErr != nil {
|
if buildErr != nil {
|
||||||
@@ -87,15 +104,7 @@ func ReconcileProviders(oldCfg, newCfg *config.Config, existing []Provider) (res
|
|||||||
if buildErr != nil {
|
if buildErr != nil {
|
||||||
return nil, nil, nil, nil, buildErr
|
return nil, nil, nil, nil, buildErr
|
||||||
}
|
}
|
||||||
if _, ok := oldCfgMap[key]; ok {
|
added = append(added, key)
|
||||||
if _, existed := existingMap[key]; existed {
|
|
||||||
updated = append(updated, key)
|
|
||||||
} else {
|
|
||||||
added = append(added, key)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
added = append(added, key)
|
|
||||||
}
|
|
||||||
result = append(result, provider)
|
result = append(result, provider)
|
||||||
}
|
}
|
||||||
finalIDs[key] = struct{}{}
|
finalIDs[key] = struct{}{}
|
||||||
|
|||||||
Reference in New Issue
Block a user