Prechádzať zdrojové kódy

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

CaIon 10 mesiacov pred
rodič
commit
da6423de33
1 zmenil súbory, kde vykonal 3 pridanie a 1 odobranie
  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")
 	}