Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a3bb88c2
authored
Dec 17, 2024
by
Calcium-Ion
Committed by
GitHub
Dec 17, 2024
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #630 from xqx333/main
修复自动禁用会对数据库进行多次更新的问题
parents
c6ec3c95
5664d557
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
0 deletions
+24
-0
model/cache.go
+11
-0
model/channel.go
+13
-0
No files found.
model/cache.go
View file @
a3bb88c2
...
...
@@ -342,3 +342,14 @@ func CacheGetChannel(id int) (*Channel, error) {
}
return
c
,
nil
}
func
CacheUpdateChannelStatus
(
id
int
,
status
int
)
{
if
(
!
common
.
MemoryCacheEnabled
)
{
return
}
channelSyncLock
.
Lock
()
defer
channelSyncLock
.
Unlock
()
if
channel
,
ok
:=
channelsIDM
[
id
];
ok
{
channel
.
Status
=
status
}
}
model/channel.go
View file @
a3bb88c2
...
...
@@ -4,6 +4,7 @@ import (
"encoding/json"
"one-api/common"
"strings"
"sync"
"gorm.io/gorm"
)
...
...
@@ -290,7 +291,19 @@ func (channel *Channel) Delete() error {
return
err
}
var
channelStatusLock
sync
.
Mutex
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
)
if
err
!=
nil
{
common
.
SysError
(
"failed to update ability status: "
+
err
.
Error
())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment