Selaa lähdekoodia

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

CaIon 8 kuukautta sitten
vanhempi
sitoutus
da6423de33
1 muutettua tiedostoa jossa 3 lisäystä ja 1 poistoa
  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")
 	}