refactor: Reducing the lock duration to the minimum necessary time in CacheGetRandomSatisfiedChannel function

This commit is contained in:
CaIon
2025-04-29 15:57:21 +08:00
parent fe37718259
commit da6423de33

View File

@@ -84,9 +84,11 @@ func CacheGetRandomSatisfiedChannel(group string, model string, retry int) (*Cha
if !common.MemoryCacheEnabled { if !common.MemoryCacheEnabled {
return GetRandomSatisfiedChannel(group, model, retry) return GetRandomSatisfiedChannel(group, model, retry)
} }
channelSyncLock.RLock() channelSyncLock.RLock()
defer channelSyncLock.RUnlock()
channels := group2model2channels[group][model] channels := group2model2channels[group][model]
channelSyncLock.RUnlock()
if len(channels) == 0 { if len(channels) == 0 {
return nil, errors.New("channel not found") return nil, errors.New("channel not found")
} }