|
@@ -4,6 +4,7 @@ import (
|
|
|
"encoding/json"
|
|
"encoding/json"
|
|
|
"one-api/common"
|
|
"one-api/common"
|
|
|
"strings"
|
|
"strings"
|
|
|
|
|
+ "sync"
|
|
|
|
|
|
|
|
"gorm.io/gorm"
|
|
"gorm.io/gorm"
|
|
|
)
|
|
)
|
|
@@ -290,7 +291,19 @@ func (channel *Channel) Delete() error {
|
|
|
return err
|
|
return err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+var channelStatusLock sync.Mutex
|
|
|
func UpdateChannelStatusById(id int, status int, reason string) {
|
|
func UpdateChannelStatusById(id int, status int, reason string) {
|
|
|
|
|
+ if (common.MemoryCacheEnabled) {
|
|
|
|
|
+ channelStatusLock.Lock()
|
|
|
|
|
+ channelCache, err := CacheGetChannel(id)
|
|
|
|
|
+ // 如果缓存渠道不存在或渠道已是目标状态,直接返回
|
|
|
|
|
+ if err != nil || channelCache.Status == status {
|
|
|
|
|
+ channelStatusLock.Unlock()
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ CacheUpdateChannelStatus(id, status)
|
|
|
|
|
+ channelStatusLock.Unlock()
|
|
|
|
|
+ }
|
|
|
err := UpdateAbilityStatus(id, status == common.ChannelStatusEnabled)
|
|
err := UpdateAbilityStatus(id, status == common.ChannelStatusEnabled)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
common.SysError("failed to update ability status: " + err.Error())
|
|
common.SysError("failed to update ability status: " + err.Error())
|