Explorar o código

fix: 修复被禁用的渠道无法测试的问题

CaIon hai 5 meses
pai
achega
196bafff03
Modificáronse 2 ficheiros con 19 adicións e 2 borrados
  1. 5 2
      controller/channel-test.go
  2. 14 0
      model/channel_cache.go

+ 5 - 2
controller/channel-test.go

@@ -332,8 +332,11 @@ func TestChannel(c *gin.Context) {
 	}
 	channel, err := model.CacheGetChannel(channelId)
 	if err != nil {
-		common.ApiError(c, err)
-		return
+		channel, err = model.GetChannelById(channelId, true)
+		if err != nil {
+			common.ApiError(c, err)
+			return
+		}
 	}
 	//defer func() {
 	//	if channel.ChannelInfo.IsMultiKey {

+ 14 - 0
model/channel_cache.go

@@ -239,6 +239,20 @@ func CacheUpdateChannelStatus(id int, status int) {
 	if channel, ok := channelsIDM[id]; ok {
 		channel.Status = status
 	}
+	if status != common.ChannelStatusEnabled {
+		// delete the channel from group2model2channels
+		for group, model2channels := range group2model2channels {
+			for model, channels := range model2channels {
+				for i, channelId := range channels {
+					if channelId == id {
+						// remove the channel from the slice
+						group2model2channels[group][model] = append(channels[:i], channels[i+1:]...)
+						break
+					}
+				}
+			}
+		}
+	}
 }
 
 func CacheUpdateChannel(channel *Channel) {