Skip to content

Commit 2491e9b

Browse files
author
QTom
committed
fix: round-3 review fixes for RPM limiting
- Add sanitizeExtraBaseRPM to BulkUpdate handler (was missing) - Add WindowCost scheduling checks to legacy non-sticky selection paths (4 sites), matching existing sticky + load-aware coverage - Export ParseExtraInt from service package, remove duplicate parseExtraIntForValidation from admin handler
1 parent e63c839 commit 2491e9b

3 files changed

Lines changed: 21 additions & 22 deletions

File tree

backend/internal/handler/admin/account_handler.go

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,8 @@ func (h *AccountHandler) BulkUpdate(c *gin.Context) {
10821082
response.BadRequest(c, "rate_multiplier must be >= 0")
10831083
return
10841084
}
1085+
// base_rpm 输入校验:负值归零,超过 10000 截断
1086+
sanitizeExtraBaseRPM(req.Extra)
10851087

10861088
// 确定是否跳过混合渠道检查
10871089
skipCheck := req.ConfirmMixedChannelRisk != nil && *req.ConfirmMixedChannelRisk
@@ -1751,7 +1753,7 @@ func sanitizeExtraBaseRPM(extra map[string]any) {
17511753
if !ok {
17521754
return
17531755
}
1754-
v := parseExtraIntForValidation(raw)
1756+
v := service.ParseExtraInt(raw)
17551757
if v < 0 {
17561758
v = 0
17571759
} else if v > 10000 {
@@ -1760,24 +1762,3 @@ func sanitizeExtraBaseRPM(extra map[string]any) {
17601762
extra["base_rpm"] = v
17611763
}
17621764

1763-
// parseExtraIntForValidation 从 extra 字段的 any 值解析为 int,用于输入校验。
1764-
// 支持 int, int64, float64, json.Number, string 类型。
1765-
func parseExtraIntForValidation(value any) int {
1766-
switch v := value.(type) {
1767-
case int:
1768-
return v
1769-
case int64:
1770-
return int(v)
1771-
case float64:
1772-
return int(v)
1773-
case json.Number:
1774-
if i, err := v.Int64(); err == nil {
1775-
return int(i)
1776-
}
1777-
case string:
1778-
if i, err := strconv.Atoi(strings.TrimSpace(v)); err == nil {
1779-
return i
1780-
}
1781-
}
1782-
return 0
1783-
}

backend/internal/service/account.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,6 +1274,12 @@ func parseExtraFloat64(value any) float64 {
12741274
}
12751275

12761276
// parseExtraInt 从 extra 字段解析 int 值
1277+
// ParseExtraInt 从 extra 字段的 any 值解析为 int。
1278+
// 支持 int, int64, float64, json.Number, string 类型,无法解析时返回 0。
1279+
func ParseExtraInt(value any) int {
1280+
return parseExtraInt(value)
1281+
}
1282+
12771283
func parseExtraInt(value any) int {
12781284
switch v := value.(type) {
12791285
case int:

backend/internal/service/gateway_service.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2641,6 +2641,9 @@ func (s *GatewayService) selectAccountForModelWithPlatform(ctx context.Context,
26412641
if !s.isAccountSchedulableForModelSelection(ctx, acc, requestedModel) {
26422642
continue
26432643
}
2644+
if !s.isAccountSchedulableForWindowCost(ctx, acc, false) {
2645+
continue
2646+
}
26442647
if !s.isAccountSchedulableForRPM(ctx, acc, false) {
26452648
continue
26462649
}
@@ -2737,6 +2740,9 @@ func (s *GatewayService) selectAccountForModelWithPlatform(ctx context.Context,
27372740
if !s.isAccountSchedulableForModelSelection(ctx, acc, requestedModel) {
27382741
continue
27392742
}
2743+
if !s.isAccountSchedulableForWindowCost(ctx, acc, false) {
2744+
continue
2745+
}
27402746
if !s.isAccountSchedulableForRPM(ctx, acc, false) {
27412747
continue
27422748
}
@@ -2865,6 +2871,9 @@ func (s *GatewayService) selectAccountWithMixedScheduling(ctx context.Context, g
28652871
if !s.isAccountSchedulableForModelSelection(ctx, acc, requestedModel) {
28662872
continue
28672873
}
2874+
if !s.isAccountSchedulableForWindowCost(ctx, acc, false) {
2875+
continue
2876+
}
28682877
if !s.isAccountSchedulableForRPM(ctx, acc, false) {
28692878
continue
28702879
}
@@ -2963,6 +2972,9 @@ func (s *GatewayService) selectAccountWithMixedScheduling(ctx context.Context, g
29632972
if !s.isAccountSchedulableForModelSelection(ctx, acc, requestedModel) {
29642973
continue
29652974
}
2975+
if !s.isAccountSchedulableForWindowCost(ctx, acc, false) {
2976+
continue
2977+
}
29662978
if !s.isAccountSchedulableForRPM(ctx, acc, false) {
29672979
continue
29682980
}

0 commit comments

Comments
 (0)