From da6423de33524bbe760f4a65fe7e4cda8e3b8a1e Mon Sep 17 00:00:00 2001 From: CaIon <1808837298@qq.com> Date: Tue, 29 Apr 2025 15:57:21 +0800 Subject: [PATCH] refactor: Reducing the lock duration to the minimum necessary time in CacheGetRandomSatisfiedChannel function --- model/cache.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/model/cache.go b/model/cache.go index bda1ed57..2d1c36bf 100644 --- a/model/cache.go +++ b/model/cache.go @@ -84,9 +84,11 @@ func CacheGetRandomSatisfiedChannel(group string, model string, retry int) (*Cha if !common.MemoryCacheEnabled { return GetRandomSatisfiedChannel(group, model, retry) } + channelSyncLock.RLock() - defer channelSyncLock.RUnlock() channels := group2model2channels[group][model] + channelSyncLock.RUnlock() + if len(channels) == 0 { return nil, errors.New("channel not found") }