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
5d2c125d
authored
Mar 02, 2024
by
1808837298@qq.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: Improve handling of small weights in channel selection logic
parent
a67859a2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
3 deletions
+6
-3
model/cache.go
+6
-3
No files found.
model/cache.go
View file @
5d2c125d
...
...
@@ -291,10 +291,13 @@ func CacheGetRandomSatisfiedChannel(group string, model string) (*Channel, error
}
}
}
// 平滑系数
smoothingFactor
:=
10
// Calculate the total weight of all channels up to endIdx
totalWeight
:=
0
for
_
,
channel
:=
range
channels
[
:
endIdx
]
{
totalWeight
+=
channel
.
GetWeight
()
totalWeight
+=
channel
.
GetWeight
()
+
smoothingFactor
}
if
totalWeight
==
0
{
...
...
@@ -307,8 +310,8 @@ func CacheGetRandomSatisfiedChannel(group string, model string) (*Channel, error
// Find a channel based on its weight
for
_
,
channel
:=
range
channels
[
:
endIdx
]
{
randomWeight
-=
channel
.
GetWeight
()
if
randomWeight
<
=
0
{
randomWeight
-=
channel
.
GetWeight
()
+
smoothingFactor
if
randomWeight
<
0
{
return
channel
,
nil
}
}
...
...
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