Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
f648b8e0
"...internal/handler/git@web.lueluesay.top:chenxi/sub2api.git" did not exist on "0fba1901c8d5a494e9501c4e96a17dfc537b6bdf"
Commit
f648b8e0
authored
Feb 28, 2026
by
QTom
Browse files
feat: increment RPM counter before request forwarding
parent
678c3ae1
Changes
2
Hide whitespace changes
Inline
Side-by-side
backend/internal/handler/gateway_handler.go
View file @
f648b8e0
...
...
@@ -366,6 +366,13 @@ func (h *GatewayHandler) Messages(c *gin.Context) {
// 账号槽位/等待计数需要在超时或断开时安全回收
accountReleaseFunc
=
wrapReleaseOnDone
(
c
.
Request
.
Context
(),
accountReleaseFunc
)
// RPM 计数递增(调度成功后、Forward 前)
if
account
.
IsAnthropicOAuthOrSetupToken
()
&&
account
.
GetBaseRPM
()
>
0
{
if
h
.
gatewayService
.
IncrementAccountRPM
(
c
.
Request
.
Context
(),
account
.
ID
)
!=
nil
{
// 失败开放:不阻塞请求
}
}
// 转发请求 - 根据账号平台分流
var
result
*
service
.
ForwardResult
requestCtx
:=
c
.
Request
.
Context
()
...
...
@@ -549,6 +556,13 @@ func (h *GatewayHandler) Messages(c *gin.Context) {
// 账号槽位/等待计数需要在超时或断开时安全回收
accountReleaseFunc
=
wrapReleaseOnDone
(
c
.
Request
.
Context
(),
accountReleaseFunc
)
// RPM 计数递增(调度成功后、Forward 前)
if
account
.
IsAnthropicOAuthOrSetupToken
()
&&
account
.
GetBaseRPM
()
>
0
{
if
h
.
gatewayService
.
IncrementAccountRPM
(
c
.
Request
.
Context
(),
account
.
ID
)
!=
nil
{
// 失败开放:不阻塞请求
}
}
// 转发请求 - 根据账号平台分流
var
result
*
service
.
ForwardResult
requestCtx
:=
c
.
Request
.
Context
()
...
...
backend/internal/service/gateway_service.go
View file @
f648b8e0
...
...
@@ -2241,6 +2241,15 @@ func (s *GatewayService) isAccountSchedulableForRPM(ctx context.Context, account
return
true
}
// IncrementAccountRPM increments the RPM counter for the given account.
func
(
s
*
GatewayService
)
IncrementAccountRPM
(
ctx
context
.
Context
,
accountID
int64
)
error
{
if
s
.
rpmCache
==
nil
{
return
nil
}
_
,
err
:=
s
.
rpmCache
.
IncrementRPM
(
ctx
,
accountID
)
return
err
}
// checkAndRegisterSession 检查并注册会话,用于会话数量限制
// 仅适用于 Anthropic OAuth/SetupToken 账号
// sessionID: 会话标识符(使用粘性会话的 hash)
...
...
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