mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-19 16:17:56 +00:00
fix: 选号读取分组时不再聚合账号数
- 推理选号只需要隐私开关和分组名,改为 GetByIDLite - 避免 GetByID 附带的账号计数聚合打满主库 - 管理列表的实时账号数统计保持不变
This commit is contained in:
@@ -3361,8 +3361,8 @@ func TestGatewayService_GroupResolution_ReusesContextGroup(t *testing.T) {
|
||||
account, err := svc.SelectAccountForModelWithExclusions(ctx, &groupID, "", "claude-3-5-sonnet-20241022", nil)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, account)
|
||||
require.Equal(t, 1, groupRepo.getByIDCalls) // +1 for require_privacy_set check
|
||||
require.Equal(t, 0, groupRepo.getByIDLiteCalls)
|
||||
require.Equal(t, 0, groupRepo.getByIDCalls)
|
||||
require.Equal(t, 1, groupRepo.getByIDLiteCalls) // require_privacy_set,不走账号计数聚合
|
||||
}
|
||||
|
||||
func TestGatewayService_GroupResolution_IgnoresInvalidContextGroup(t *testing.T) {
|
||||
@@ -3404,8 +3404,8 @@ func TestGatewayService_GroupResolution_IgnoresInvalidContextGroup(t *testing.T)
|
||||
account, err := svc.SelectAccountForModelWithExclusions(ctx, &groupID, "", "claude-3-5-sonnet-20241022", nil)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, account)
|
||||
require.Equal(t, 1, groupRepo.getByIDCalls) // +1 for require_privacy_set check
|
||||
require.Equal(t, 1, groupRepo.getByIDLiteCalls)
|
||||
require.Equal(t, 0, groupRepo.getByIDCalls)
|
||||
require.Equal(t, 2, groupRepo.getByIDLiteCalls) // 分组解析 + require_privacy_set
|
||||
}
|
||||
|
||||
func TestGatewayService_GroupContext_OverwritesInvalidContextGroup(t *testing.T) {
|
||||
@@ -3474,8 +3474,8 @@ func TestGatewayService_GroupResolution_FallbackUsesLiteOnce(t *testing.T) {
|
||||
account, err := svc.SelectAccountForModelWithExclusions(ctx, &groupID, "", "claude-3-5-sonnet-20241022", nil)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, account)
|
||||
require.Equal(t, 1, groupRepo.getByIDCalls) // +1 for require_privacy_set check
|
||||
require.Equal(t, 1, groupRepo.getByIDLiteCalls)
|
||||
require.Equal(t, 0, groupRepo.getByIDCalls)
|
||||
require.Equal(t, 2, groupRepo.getByIDLiteCalls) // fallback 解析 + require_privacy_set
|
||||
}
|
||||
|
||||
func TestGatewayService_ResolveGatewayGroup_DetectsFallbackCycle(t *testing.T) {
|
||||
|
||||
@@ -1893,10 +1893,10 @@ func (s *GatewayService) selectAccountForModelWithPlatform(ctx context.Context,
|
||||
preferOAuth := platform == PlatformGemini
|
||||
routingAccountIDs := s.routingAccountIDsForRequest(ctx, groupID, requestedModel, platform)
|
||||
|
||||
// require_privacy_set: 获取分组信息
|
||||
// require_privacy_set: 获取分组配置。GetByID 会聚合账号计数,旧选号路径不能用它。
|
||||
var schedGroup *Group
|
||||
if groupID != nil && s.groupRepo != nil {
|
||||
schedGroup, _ = s.groupRepo.GetByID(ctx, *groupID)
|
||||
schedGroup, _ = s.groupRepo.GetByIDLite(ctx, *groupID)
|
||||
}
|
||||
|
||||
var accounts []Account
|
||||
@@ -2159,10 +2159,10 @@ func (s *GatewayService) selectAccountWithMixedScheduling(ctx context.Context, g
|
||||
preferOAuth := nativePlatform == PlatformGemini
|
||||
routingAccountIDs := s.routingAccountIDsForRequest(ctx, groupID, requestedModel, nativePlatform)
|
||||
|
||||
// require_privacy_set: 获取分组信息
|
||||
// require_privacy_set: 获取分组配置。GetByID 会聚合账号计数,旧选号路径不能用它。
|
||||
var schedGroup *Group
|
||||
if groupID != nil && s.groupRepo != nil {
|
||||
schedGroup, _ = s.groupRepo.GetByID(ctx, *groupID)
|
||||
schedGroup, _ = s.groupRepo.GetByIDLite(ctx, *groupID)
|
||||
}
|
||||
|
||||
var accounts []Account
|
||||
|
||||
@@ -1432,10 +1432,10 @@ func (s *defaultOpenAIAccountScheduler) selectByLoadBalance(
|
||||
accounts = modelFiltered
|
||||
}
|
||||
|
||||
// require_privacy_set: 获取分组信息
|
||||
// require_privacy_set: 获取分组配置。GetByID 会聚合账号计数,选号不能走它。
|
||||
var schedGroup *Group
|
||||
if req.GroupID != nil && s.service.schedulerSnapshot != nil {
|
||||
schedGroup, _ = s.service.schedulerSnapshot.GetGroupByID(ctx, *req.GroupID)
|
||||
schedGroup, _ = s.service.schedulerSnapshot.GetGroupByIDLite(ctx, *req.GroupID)
|
||||
}
|
||||
|
||||
filterStats := openAISelectionFilterStats{pool: len(accounts)}
|
||||
@@ -2214,7 +2214,8 @@ func (s *OpenAIGatewayService) loadOpenAIGroupRequiresPrivacySet(ctx context.Con
|
||||
if s == nil || groupID == nil || s.schedulerSnapshot == nil {
|
||||
return false
|
||||
}
|
||||
group, err := s.schedulerSnapshot.GetGroupByID(ctx, *groupID)
|
||||
// GetByID 会聚合账号计数;隐私开关只在分组行上。
|
||||
group, err := s.schedulerSnapshot.GetGroupByIDLite(ctx, *groupID)
|
||||
if err != nil {
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user