Преглед на файлове

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

CaIon преди 10 месеца
родител
ревизия
da6423de33
променени са 1 файла, в които са добавени 3 реда и са изтрити 1 реда
  1. 3 1
      model/cache.go

+ 3 - 1
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")
 	}