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
fa7d18ab
authored
Jun 13, 2025
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🔒
feat(setting): add mutex for GroupGroupRatio to ensure thread safety
parent
2a0bf7f9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
5 deletions
+17
-5
setting/group_ratio.go
+17
-5
No files found.
setting/group_ratio.go
View file @
fa7d18ab
...
...
@@ -14,11 +14,14 @@ var groupRatio = map[string]float64{
}
var
groupRatioMutex
sync
.
RWMutex
var
GroupGroupRatio
=
map
[
string
]
map
[
string
]
float64
{
"vip"
:
{
"edit_this"
:
0.9
,
},
}
var
(
GroupGroupRatio
=
map
[
string
]
map
[
string
]
float64
{
"vip"
:
{
"edit_this"
:
0.9
,
},
}
groupGroupRatioMutex
sync
.
RWMutex
)
func
GetGroupRatioCopy
()
map
[
string
]
float64
{
groupRatioMutex
.
RLock
()
...
...
@@ -71,6 +74,9 @@ func GetGroupRatio(name string) float64 {
}
func
GetGroupGroupRatio
(
group
,
name
string
)
(
float64
,
bool
)
{
groupGroupRatioMutex
.
RLock
()
defer
groupGroupRatioMutex
.
RUnlock
()
gp
,
ok
:=
GroupGroupRatio
[
group
]
if
!
ok
{
return
-
1
,
false
...
...
@@ -83,6 +89,9 @@ func GetGroupGroupRatio(group, name string) (float64, bool) {
}
func
GroupGroupRatio2JSONString
()
string
{
groupGroupRatioMutex
.
RLock
()
defer
groupGroupRatioMutex
.
RUnlock
()
jsonBytes
,
err
:=
json
.
Marshal
(
GroupGroupRatio
)
if
err
!=
nil
{
common
.
SysError
(
"error marshalling group-group ratio: "
+
err
.
Error
())
...
...
@@ -91,6 +100,9 @@ func GroupGroupRatio2JSONString() string {
}
func
UpdateGroupGroupRatioByJSONString
(
jsonStr
string
)
error
{
groupGroupRatioMutex
.
Lock
()
defer
groupGroupRatioMutex
.
Unlock
()
GroupGroupRatio
=
make
(
map
[
string
]
map
[
string
]
float64
)
return
json
.
Unmarshal
([]
byte
(
jsonStr
),
&
GroupGroupRatio
)
}
...
...
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