From 7fbc59eb698ea9d75cc9be9ac0b3b0c6f11127a5 Mon Sep 17 00:00:00 2001 From: spongehah <2635879218@qq.com> Date: Tue, 22 Sep 2026 16:54:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=80=89=E5=8F=B7=E8=AF=BB=E5=8F=96?= =?UTF-8?q?=E5=88=86=E7=BB=84=E6=97=B6=E4=B8=8D=E5=86=8D=E8=81=9A=E5=90=88?= =?UTF-8?q?=E8=B4=A6=E5=8F=B7=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 推理选号只需要隐私开关和分组名,改为 GetByIDLite - 避免 GetByID 附带的账号计数聚合打满主库 - 管理列表的实时账号数统计保持不变 --- .../internal/service/gateway_multiplatform_test.go | 12 ++++++------ backend/internal/service/gateway_scheduling.go | 8 ++++---- backend/internal/service/openai_account_scheduler.go | 7 ++++--- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/backend/internal/service/gateway_multiplatform_test.go b/backend/internal/service/gateway_multiplatform_test.go index 6568b3f6b4..badb2427cf 100644 --- a/backend/internal/service/gateway_multiplatform_test.go +++ b/backend/internal/service/gateway_multiplatform_test.go @@ -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) { diff --git a/backend/internal/service/gateway_scheduling.go b/backend/internal/service/gateway_scheduling.go index f5dd160c79..059d7e2b2c 100644 --- a/backend/internal/service/gateway_scheduling.go +++ b/backend/internal/service/gateway_scheduling.go @@ -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 diff --git a/backend/internal/service/openai_account_scheduler.go b/backend/internal/service/openai_account_scheduler.go index 28e30dfadf..3cf56f234e 100644 --- a/backend/internal/service/openai_account_scheduler.go +++ b/backend/internal/service/openai_account_scheduler.go @@ -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 }