fix: caching
This commit is contained in:
parent
26f50b7fd4
commit
c52f5ad997
@ -203,25 +203,27 @@ func CacheGetRandomSatisfiedChannel(group string, model string, stream bool) (*C
|
|||||||
}
|
}
|
||||||
|
|
||||||
var filteredChannels []*Channel
|
var filteredChannels []*Channel
|
||||||
|
|
||||||
for _, channel := range channels {
|
for _, channel := range channels {
|
||||||
if (stream && channel.AllowStreaming == common.ChannelAllowStreamEnabled) || (!stream && channel.AllowNonStreaming == common.ChannelAllowNonStreamEnabled) {
|
isStreaming := stream && channel.AllowStreaming == common.ChannelAllowStreamEnabled
|
||||||
|
isNotStreaming := !stream && channel.AllowNonStreaming == common.ChannelAllowNonStreamEnabled
|
||||||
|
|
||||||
|
if isStreaming || isNotStreaming {
|
||||||
filteredChannels = append(filteredChannels, channel)
|
filteredChannels = append(filteredChannels, channel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
endIdx := len(channels)
|
endIdx := len(filteredChannels)
|
||||||
|
|
||||||
// choose by priority
|
// choose by priority
|
||||||
firstChannel := channels[0]
|
firstChannel := filteredChannels[0]
|
||||||
if firstChannel.GetPriority() > 0 {
|
if firstChannel.GetPriority() > 0 {
|
||||||
for i := range channels {
|
for i := range filteredChannels {
|
||||||
if channels[i].GetPriority() != firstChannel.GetPriority() {
|
if filteredChannels[i].GetPriority() != firstChannel.GetPriority() {
|
||||||
endIdx = i
|
endIdx = i
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
idx := rand.Intn(endIdx)
|
idx := rand.Intn(endIdx)
|
||||||
return filteredChannels[idx], nil
|
return filteredChannels[idx], nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user