From e8e5acb9e79a34a11981341c008d3ab9f4fad058 Mon Sep 17 00:00:00 2001 From: erio Date: Fri, 6 Mar 2026 18:47:52 +0800 Subject: [PATCH] revert: remove client affinity count display infrastructure Remove frontend badge/tooltip and backend counting/query infrastructure for client affinity. Core client affinity scheduling logic is preserved. Removed: - GatewayCache injection in AccountHandler - GetAccountAffinityCount/Batch/Clients methods and interface - AffinityClientInfo struct and ClientAffinityTTL function - /affinity-clients API endpoint and route - Reverse index (account_affinity:*) Lua scripts - Frontend blue badge, tooltip, and lazy-load logic - affinity_client_count field from types and response Co-Authored-By: Claude Opus 4.6 --- backend/cmd/server/wire_gen.go | 2 +- .../admin/account_data_handler_test.go | 1 - .../internal/handler/admin/account_handler.go | 54 +------ .../account_handler_mixed_channel_test.go | 2 +- .../admin/account_handler_passthrough_test.go | 1 - .../admin/batch_update_credentials_test.go | 2 +- backend/internal/repository/gateway_cache.go | 143 +----------------- backend/internal/server/api_contract_test.go | 2 +- backend/internal/server/routes/admin.go | 1 - .../service/antigravity_smart_retry_test.go | 9 -- .../gateway_hotpath_optimization_test.go | 9 -- .../service/gateway_multiplatform_test.go | 9 -- backend/internal/service/gateway_service.go | 19 --- .../service/gemini_multiplatform_test.go | 9 -- .../service/openai_gateway_service_test.go | 9 -- .../service/openai_ws_state_store_test.go | 9 -- backend/internal/testutil/stubs.go | 9 -- .../account/AccountStatusIndicator.vue | 66 +------- frontend/src/types/index.ts | 1 - 19 files changed, 15 insertions(+), 342 deletions(-) diff --git a/backend/cmd/server/wire_gen.go b/backend/cmd/server/wire_gen.go index f8930ae660..60bb17d51d 100644 --- a/backend/cmd/server/wire_gen.go +++ b/backend/cmd/server/wire_gen.go @@ -140,7 +140,7 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) { crsSyncService := service.NewCRSSyncService(accountRepository, proxyRepository, oAuthService, openAIOAuthService, geminiOAuthService, configConfig) sessionLimitCache := repository.ProvideSessionLimitCache(redisClient, configConfig) rpmCache := repository.NewRPMCache(redisClient) - accountHandler := admin.NewAccountHandler(adminService, oAuthService, openAIOAuthService, geminiOAuthService, antigravityOAuthService, rateLimitService, accountUsageService, accountTestService, concurrencyService, crsSyncService, sessionLimitCache, rpmCache, compositeTokenCacheInvalidator, gatewayCache) + accountHandler := admin.NewAccountHandler(adminService, oAuthService, openAIOAuthService, geminiOAuthService, antigravityOAuthService, rateLimitService, accountUsageService, accountTestService, concurrencyService, crsSyncService, sessionLimitCache, rpmCache, compositeTokenCacheInvalidator) adminAnnouncementHandler := admin.NewAnnouncementHandler(announcementService) dataManagementService := service.NewDataManagementService() dataManagementHandler := admin.NewDataManagementHandler(dataManagementService) diff --git a/backend/internal/handler/admin/account_data_handler_test.go b/backend/internal/handler/admin/account_data_handler_test.go index e516b275f2..285033a17d 100644 --- a/backend/internal/handler/admin/account_data_handler_test.go +++ b/backend/internal/handler/admin/account_data_handler_test.go @@ -65,7 +65,6 @@ func setupAccountDataRouter() (*gin.Engine, *stubAdminService) { nil, nil, nil, - nil, ) router.GET("/api/v1/admin/accounts/data", h.ExportData) diff --git a/backend/internal/handler/admin/account_handler.go b/backend/internal/handler/admin/account_handler.go index 2fa0e20c4c..843d51c516 100644 --- a/backend/internal/handler/admin/account_handler.go +++ b/backend/internal/handler/admin/account_handler.go @@ -55,7 +55,6 @@ type AccountHandler struct { sessionLimitCache service.SessionLimitCache rpmCache service.RPMCache tokenCacheInvalidator service.TokenCacheInvalidator - gatewayCache service.GatewayCache } // NewAccountHandler creates a new admin account handler @@ -73,7 +72,6 @@ func NewAccountHandler( sessionLimitCache service.SessionLimitCache, rpmCache service.RPMCache, tokenCacheInvalidator service.TokenCacheInvalidator, - gatewayCache service.GatewayCache, ) *AccountHandler { return &AccountHandler{ adminService: adminService, @@ -89,7 +87,6 @@ func NewAccountHandler( sessionLimitCache: sessionLimitCache, rpmCache: rpmCache, tokenCacheInvalidator: tokenCacheInvalidator, - gatewayCache: gatewayCache, } } @@ -161,10 +158,9 @@ type AccountWithConcurrency struct { *dto.Account CurrentConcurrency int `json:"current_concurrency"` // 以下字段仅对 Anthropic OAuth/SetupToken 账号有效,且仅在启用相应功能时返回 - CurrentWindowCost *float64 `json:"current_window_cost,omitempty"` // 当前窗口费用 - ActiveSessions *int `json:"active_sessions,omitempty"` // 当前活跃会话数 - CurrentRPM *int `json:"current_rpm,omitempty"` // 当前分钟 RPM 计数 - AffinityClientCount *int `json:"affinity_client_count,omitempty"` // 亲和客户端数量 + CurrentWindowCost *float64 `json:"current_window_cost,omitempty"` // 当前窗口费用 + ActiveSessions *int `json:"active_sessions,omitempty"` // 当前活跃会话数 + CurrentRPM *int `json:"current_rpm,omitempty"` // 当前分钟 RPM 计数 } func (h *AccountHandler) buildAccountResponseWithRuntime(ctx context.Context, account *service.Account) AccountWithConcurrency { @@ -247,7 +243,6 @@ func (h *AccountHandler) List(c *gin.Context) { var windowCosts map[int64]float64 var activeSessions map[int64]int var rpmCounts map[int64]int - var affinityCounts map[int64]int // 始终获取并发数(Redis ZCARD,极低开销) if h.concurrencyService != nil { @@ -256,11 +251,10 @@ func (h *AccountHandler) List(c *gin.Context) { } } - // 识别需要查询窗口费用、会话数、RPM 和亲和客户端的账号(Anthropic OAuth/SetupToken 且启用了相应功能) + // 识别需要查询窗口费用、会话数和 RPM 的账号(Anthropic OAuth/SetupToken 且启用了相应功能) windowCostAccountIDs := make([]int64, 0) sessionLimitAccountIDs := make([]int64, 0) rpmAccountIDs := make([]int64, 0) - affinityAccountIDs := make([]int64, 0) sessionIdleTimeouts := make(map[int64]time.Duration) // 各账号的会话空闲超时配置 for i := range accounts { acc := &accounts[i] @@ -275,9 +269,6 @@ func (h *AccountHandler) List(c *gin.Context) { if acc.GetBaseRPM() > 0 { rpmAccountIDs = append(rpmAccountIDs, acc.ID) } - if acc.IsClientAffinityEnabled() { - affinityAccountIDs = append(affinityAccountIDs, acc.ID) - } } } @@ -297,11 +288,6 @@ func (h *AccountHandler) List(c *gin.Context) { } } - // 获取亲和客户端数量(Redis pipeline,低开销) - if len(affinityAccountIDs) > 0 && h.gatewayCache != nil { - affinityCounts, _ = h.gatewayCache.GetAccountAffinityCountBatch(c.Request.Context(), affinityAccountIDs, service.ClientAffinityTTL()) - } - // 窗口费用获取:lite 模式从快照缓存读取,非 lite 模式执行 PostgreSQL 查询后写入缓存 if len(windowCostAccountIDs) > 0 { if lite { @@ -376,13 +362,6 @@ func (h *AccountHandler) List(c *gin.Context) { } } - // 添加亲和客户端数量(仅当启用时) - if affinityCounts != nil { - if count, ok := affinityCounts[acc.ID]; ok { - item.AffinityClientCount = &count - } - } - result[i] = item } @@ -1873,28 +1852,3 @@ func sanitizeExtraBaseRPM(extra map[string]any) { } extra["base_rpm"] = v } - -// GetAffinityClients 返回指定账号的亲和客户端列表 -// GET /api/v1/admin/accounts/:id/affinity-clients -func (h *AccountHandler) GetAffinityClients(c *gin.Context) { - id, err := strconv.ParseInt(c.Param("id"), 10, 64) - if err != nil { - response.Error(c, http.StatusBadRequest, "invalid id") - return - } - - if h.gatewayCache == nil { - response.Success(c, []service.AffinityClientInfo{}) - return - } - - clients, err := h.gatewayCache.GetAccountAffinityClients(c.Request.Context(), id, service.ClientAffinityTTL()) - if err != nil { - response.ErrorFrom(c, err) - return - } - if clients == nil { - clients = []service.AffinityClientInfo{} - } - response.Success(c, clients) -} diff --git a/backend/internal/handler/admin/account_handler_mixed_channel_test.go b/backend/internal/handler/admin/account_handler_mixed_channel_test.go index 5e45619064..5b81db2aad 100644 --- a/backend/internal/handler/admin/account_handler_mixed_channel_test.go +++ b/backend/internal/handler/admin/account_handler_mixed_channel_test.go @@ -15,7 +15,7 @@ import ( func setupAccountMixedChannelRouter(adminSvc *stubAdminService) *gin.Engine { gin.SetMode(gin.TestMode) router := gin.New() - accountHandler := NewAccountHandler(adminSvc, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) + accountHandler := NewAccountHandler(adminSvc, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) router.POST("/api/v1/admin/accounts/check-mixed-channel", accountHandler.CheckMixedChannel) router.POST("/api/v1/admin/accounts", accountHandler.Create) router.PUT("/api/v1/admin/accounts/:id", accountHandler.Update) diff --git a/backend/internal/handler/admin/account_handler_passthrough_test.go b/backend/internal/handler/admin/account_handler_passthrough_test.go index a11f2c5195..d86501c047 100644 --- a/backend/internal/handler/admin/account_handler_passthrough_test.go +++ b/backend/internal/handler/admin/account_handler_passthrough_test.go @@ -29,7 +29,6 @@ func TestAccountHandler_Create_AnthropicAPIKeyPassthroughExtraForwarded(t *testi nil, nil, nil, - nil, ) router := gin.New() diff --git a/backend/internal/handler/admin/batch_update_credentials_test.go b/backend/internal/handler/admin/batch_update_credentials_test.go index f2cd1e3a1c..0b1b669174 100644 --- a/backend/internal/handler/admin/batch_update_credentials_test.go +++ b/backend/internal/handler/admin/batch_update_credentials_test.go @@ -36,7 +36,7 @@ func (f *failingAdminService) UpdateAccount(ctx context.Context, id int64, input func setupAccountHandlerWithService(adminSvc service.AdminService) (*gin.Engine, *AccountHandler) { gin.SetMode(gin.TestMode) router := gin.New() - handler := NewAccountHandler(adminSvc, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) + handler := NewAccountHandler(adminSvc, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) router.POST("/api/v1/admin/accounts/batch-update-credentials", handler.BatchUpdateCredentials) return router, handler } diff --git a/backend/internal/repository/gateway_cache.go b/backend/internal/repository/gateway_cache.go index 462a51b7a2..8fa6d0c401 100644 --- a/backend/internal/repository/gateway_cache.go +++ b/backend/internal/repository/gateway_cache.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "strconv" - "strings" "time" "github.com/Wei-Shaw/sub2api/internal/service" @@ -12,9 +11,8 @@ import ( ) const ( - stickySessionPrefix = "sticky_session:" - clientAffinityPrefix = "client_affinity:" - accountAffinityPrefix = "account_affinity:" + stickySessionPrefix = "sticky_session:" + clientAffinityPrefix = "client_affinity:" ) type gatewayCache struct { @@ -72,21 +70,16 @@ redis.call('ZREMRANGEBYSCORE', KEYS[1], '-inf', ARGV[1]) return redis.call('ZREVRANGE', KEYS[1], 0, -1) `) -// updateAffinityScript: 清理过期成员、添加/更新亲和关系、刷新 TTL, -// 同时维护反向索引 account_affinity:{accountID} +// updateAffinityScript: 清理过期成员、添加/更新亲和关系、刷新 TTL // KEYS[1] = client_affinity:{groupID}:{clientID} -// KEYS[2] = account_affinity:{accountID} // ARGV[1] = 当前时间戳 // ARGV[2] = TTL 秒数 // ARGV[3] = accountID // ARGV[4] = 过期阈值时间戳 (now - ttl) -// ARGV[5] = 反向索引成员 "{groupID}:{clientID}" var updateAffinityScript = redis.NewScript(` redis.call('ZREMRANGEBYSCORE', KEYS[1], '-inf', ARGV[4]) redis.call('ZADD', KEYS[1], ARGV[1], ARGV[3]) redis.call('EXPIRE', KEYS[1], ARGV[2]) -redis.call('ZADD', KEYS[2], ARGV[1], ARGV[5]) -redis.call('EXPIRE', KEYS[2], 86400) return 1 `) @@ -116,140 +109,16 @@ func (c *gatewayCache) GetClientAffinityAccounts(ctx context.Context, groupID in func (c *gatewayCache) UpdateClientAffinity(ctx context.Context, groupID int64, clientID string, accountID int64, ttl time.Duration) error { key := buildAffinityKey(groupID, clientID) - reverseKey := buildAccountAffinityKey(accountID) - reverseMember := fmt.Sprintf("%d:%s", groupID, clientID) now := time.Now().Unix() ttlSeconds := int64(ttl.Seconds()) expireThreshold := now - ttlSeconds - return updateAffinityScript.Run(ctx, c.rdb, []string{key, reverseKey}, - now, ttlSeconds, accountID, expireThreshold, reverseMember, + return updateAffinityScript.Run(ctx, c.rdb, []string{key}, + now, ttlSeconds, accountID, expireThreshold, ).Err() } func (c *gatewayCache) RemoveClientAffinity(ctx context.Context, groupID int64, clientID string, accountID int64) error { key := buildAffinityKey(groupID, clientID) - reverseKey := buildAccountAffinityKey(accountID) - reverseMember := fmt.Sprintf("%d:%s", groupID, clientID) - pipe := c.rdb.Pipeline() - pipe.ZRem(ctx, key, accountID) - pipe.ZRem(ctx, reverseKey, reverseMember) - _, err := pipe.Exec(ctx) - return err -} - -// buildAccountAffinityKey 构建账号亲和反向索引 key -// 格式: account_affinity:{accountID} -func buildAccountAffinityKey(accountID int64) string { - return fmt.Sprintf("%s%d", accountAffinityPrefix, accountID) -} - -// getAccountAffinityScript: 清理过期成员后返回 ZCARD,空 key 自动删除 -// KEYS[1] = account_affinity:{accountID} -// ARGV[1] = 过期阈值时间戳 (now - ttl) -var getAccountAffinityScript = redis.NewScript(` -redis.call('ZREMRANGEBYSCORE', KEYS[1], '-inf', ARGV[1]) -local count = redis.call('ZCARD', KEYS[1]) -if count == 0 then - redis.call('DEL', KEYS[1]) -end -return count -`) - -func (c *gatewayCache) GetAccountAffinityCount(ctx context.Context, accountID int64, ttl time.Duration) (int, error) { - key := buildAccountAffinityKey(accountID) - expireThreshold := time.Now().Unix() - int64(ttl.Seconds()) - - count, err := getAccountAffinityScript.Run(ctx, c.rdb, []string{key}, expireThreshold).Int() - if err != nil && err != redis.Nil { - return 0, err - } - return count, nil -} - -func (c *gatewayCache) GetAccountAffinityCountBatch(ctx context.Context, accountIDs []int64, ttl time.Duration) (map[int64]int, error) { - if len(accountIDs) == 0 { - return nil, nil - } - - expireThreshold := time.Now().Unix() - int64(ttl.Seconds()) - pipe := c.rdb.Pipeline() - cmds := make([]*redis.Cmd, len(accountIDs)) - - for i, id := range accountIDs { - key := buildAccountAffinityKey(id) - cmds[i] = getAccountAffinityScript.Run(ctx, pipe, []string{key}, expireThreshold) - } - - _, err := pipe.Exec(ctx) - if err != nil && err != redis.Nil { - return nil, err - } - - result := make(map[int64]int, len(accountIDs)) - for i, id := range accountIDs { - count, err := cmds[i].Int() - if err != nil && err != redis.Nil { - continue - } - result[id] = count - } - return result, nil -} - -// getAccountAffinityClientsScript: 清理过期成员后返回成员列表及 score -// KEYS[1] = account_affinity:{accountID} -// ARGV[1] = 过期阈值时间戳 (now - ttl) -var getAccountAffinityClientsScript = redis.NewScript(` -redis.call('ZREMRANGEBYSCORE', KEYS[1], '-inf', ARGV[1]) -return redis.call('ZRANGE', KEYS[1], 0, -1, 'WITHSCORES') -`) - -func (c *gatewayCache) GetAccountAffinityClients(ctx context.Context, accountID int64, ttl time.Duration) ([]service.AffinityClientInfo, error) { - key := buildAccountAffinityKey(accountID) - now := time.Now().Unix() - expireThreshold := now - int64(ttl.Seconds()) - - raw, err := getAccountAffinityClientsScript.Run(ctx, c.rdb, []string{key}, expireThreshold).StringSlice() - if err != nil { - if err == redis.Nil { - return nil, nil - } - return nil, err - } - - // ZRANGE WITHSCORES returns [member1, score1, member2, score2, ...] - clients := make([]service.AffinityClientInfo, 0, len(raw)/2) - for i := 0; i+1 < len(raw); i += 2 { - member := raw[i] - scoreStr := raw[i+1] - - score, parseErr := strconv.ParseInt(scoreStr, 10, 64) - if parseErr != nil { - continue - } - - // member format: "{groupID}:{clientID}" - sepIdx := strings.IndexByte(member, ':') - if sepIdx < 0 { - continue - } - groupID, parseErr := strconv.ParseInt(member[:sepIdx], 10, 64) - if parseErr != nil { - continue - } - clientID := member[sepIdx+1:] - - remaining := score + int64(ttl.Seconds()) - now - if remaining < 0 { - remaining = 0 - } - - clients = append(clients, service.AffinityClientInfo{ - GroupID: groupID, - ClientID: clientID, - TTL: remaining, - }) - } - return clients, nil + return c.rdb.ZRem(ctx, key, accountID).Err() } diff --git a/backend/internal/server/api_contract_test.go b/backend/internal/server/api_contract_test.go index 537e64b4ea..aafbbe21cb 100644 --- a/backend/internal/server/api_contract_test.go +++ b/backend/internal/server/api_contract_test.go @@ -648,7 +648,7 @@ func newContractDeps(t *testing.T) *contractDeps { apiKeyHandler := handler.NewAPIKeyHandler(apiKeyService) usageHandler := handler.NewUsageHandler(usageService, apiKeyService) adminSettingHandler := adminhandler.NewSettingHandler(settingService, nil, nil, nil, nil) - adminAccountHandler := adminhandler.NewAccountHandler(adminService, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) + adminAccountHandler := adminhandler.NewAccountHandler(adminService, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) jwtAuth := func(c *gin.Context) { c.Set(string(middleware.ContextKeyUser), middleware.AuthSubject{ diff --git a/backend/internal/server/routes/admin.go b/backend/internal/server/routes/admin.go index 46366a03b5..2e53feb36f 100644 --- a/backend/internal/server/routes/admin.go +++ b/backend/internal/server/routes/admin.go @@ -257,7 +257,6 @@ func registerAccountRoutes(admin *gin.RouterGroup, h *handler.Handlers) { accounts.DELETE("/:id/temp-unschedulable", h.Admin.Account.ClearTempUnschedulable) accounts.POST("/:id/schedulable", h.Admin.Account.SetSchedulable) accounts.GET("/:id/models", h.Admin.Account.GetAvailableModels) - accounts.GET("/:id/affinity-clients", h.Admin.Account.GetAffinityClients) accounts.POST("/batch", h.Admin.Account.BatchCreate) accounts.GET("/data", h.Admin.Account.ExportData) accounts.POST("/data", h.Admin.Account.ImportData) diff --git a/backend/internal/service/antigravity_smart_retry_test.go b/backend/internal/service/antigravity_smart_retry_test.go index a516805758..7f836bf47c 100644 --- a/backend/internal/service/antigravity_smart_retry_test.go +++ b/backend/internal/service/antigravity_smart_retry_test.go @@ -39,15 +39,6 @@ func (c *stubSmartRetryCache) UpdateClientAffinity(_ context.Context, _ int64, _ func (c *stubSmartRetryCache) RemoveClientAffinity(_ context.Context, _ int64, _ string, _ int64) error { return nil } -func (c *stubSmartRetryCache) GetAccountAffinityCount(_ context.Context, _ int64, _ time.Duration) (int, error) { - return 0, nil -} -func (c *stubSmartRetryCache) GetAccountAffinityCountBatch(_ context.Context, _ []int64, _ time.Duration) (map[int64]int, error) { - return nil, nil -} -func (c *stubSmartRetryCache) GetAccountAffinityClients(_ context.Context, _ int64, _ time.Duration) ([]AffinityClientInfo, error) { - return nil, nil -} // mockSmartRetryUpstream 用于 handleSmartRetry 测试的 mock upstream type mockSmartRetryUpstream struct { diff --git a/backend/internal/service/gateway_hotpath_optimization_test.go b/backend/internal/service/gateway_hotpath_optimization_test.go index 5eb97de993..137490e8db 100644 --- a/backend/internal/service/gateway_hotpath_optimization_test.go +++ b/backend/internal/service/gateway_hotpath_optimization_test.go @@ -152,15 +152,6 @@ func (s *stickyGatewayCacheHotpathStub) UpdateClientAffinity(_ context.Context, func (s *stickyGatewayCacheHotpathStub) RemoveClientAffinity(_ context.Context, _ int64, _ string, _ int64) error { return nil } -func (s *stickyGatewayCacheHotpathStub) GetAccountAffinityCount(_ context.Context, _ int64, _ time.Duration) (int, error) { - return 0, nil -} -func (s *stickyGatewayCacheHotpathStub) GetAccountAffinityCountBatch(_ context.Context, _ []int64, _ time.Duration) (map[int64]int, error) { - return nil, nil -} -func (s *stickyGatewayCacheHotpathStub) GetAccountAffinityClients(_ context.Context, _ int64, _ time.Duration) ([]AffinityClientInfo, error) { - return nil, nil -} func (s *modelsListAccountRepoStub) ListSchedulableByGroupID(ctx context.Context, groupID int64) ([]Account, error) { s.listByGroupCalls.Add(1) diff --git a/backend/internal/service/gateway_multiplatform_test.go b/backend/internal/service/gateway_multiplatform_test.go index c513d6b179..466ff294bb 100644 --- a/backend/internal/service/gateway_multiplatform_test.go +++ b/backend/internal/service/gateway_multiplatform_test.go @@ -244,15 +244,6 @@ func (m *mockGatewayCacheForPlatform) UpdateClientAffinity(_ context.Context, _ func (m *mockGatewayCacheForPlatform) RemoveClientAffinity(_ context.Context, _ int64, _ string, _ int64) error { return nil } -func (m *mockGatewayCacheForPlatform) GetAccountAffinityCount(_ context.Context, _ int64, _ time.Duration) (int, error) { - return 0, nil -} -func (m *mockGatewayCacheForPlatform) GetAccountAffinityCountBatch(_ context.Context, _ []int64, _ time.Duration) (map[int64]int, error) { - return nil, nil -} -func (m *mockGatewayCacheForPlatform) GetAccountAffinityClients(_ context.Context, _ int64, _ time.Duration) ([]AffinityClientInfo, error) { - return nil, nil -} type mockGroupRepoForGateway struct { groups map[int64]*Group diff --git a/backend/internal/service/gateway_service.go b/backend/internal/service/gateway_service.go index 964e1a0348..0fe2545ec0 100644 --- a/backend/internal/service/gateway_service.go +++ b/backend/internal/service/gateway_service.go @@ -375,25 +375,6 @@ type GatewayCache interface { UpdateClientAffinity(ctx context.Context, groupID int64, clientID string, accountID int64, ttl time.Duration) error // RemoveClientAffinity 删除单个客户端亲和关系 RemoveClientAffinity(ctx context.Context, groupID int64, clientID string, accountID int64) error - - // GetAccountAffinityCount 获取账号的亲和客户端数量(清理过期后) - GetAccountAffinityCount(ctx context.Context, accountID int64, ttl time.Duration) (int, error) - // GetAccountAffinityCountBatch 批量获取多个账号的亲和客户端数量 - GetAccountAffinityCountBatch(ctx context.Context, accountIDs []int64, ttl time.Duration) (map[int64]int, error) - // GetAccountAffinityClients 获取账号的亲和客户端详情列表 - GetAccountAffinityClients(ctx context.Context, accountID int64, ttl time.Duration) ([]AffinityClientInfo, error) -} - -// AffinityClientInfo 表示一个亲和客户端的详情 -type AffinityClientInfo struct { - GroupID int64 `json:"group_id"` - ClientID string `json:"client_id"` - TTL int64 `json:"ttl"` // 剩余秒数 -} - -// ClientAffinityTTL 返回客户端亲和 TTL(与粘性会话 TTL 相同) -func ClientAffinityTTL() time.Duration { - return stickySessionTTL } // derefGroupID safely dereferences *int64 to int64, returning 0 if nil diff --git a/backend/internal/service/gemini_multiplatform_test.go b/backend/internal/service/gemini_multiplatform_test.go index a08ef690b2..56f94d5f1f 100644 --- a/backend/internal/service/gemini_multiplatform_test.go +++ b/backend/internal/service/gemini_multiplatform_test.go @@ -297,15 +297,6 @@ func (m *mockGatewayCacheForGemini) UpdateClientAffinity(_ context.Context, _ in func (m *mockGatewayCacheForGemini) RemoveClientAffinity(_ context.Context, _ int64, _ string, _ int64) error { return nil } -func (m *mockGatewayCacheForGemini) GetAccountAffinityCount(_ context.Context, _ int64, _ time.Duration) (int, error) { - return 0, nil -} -func (m *mockGatewayCacheForGemini) GetAccountAffinityCountBatch(_ context.Context, _ []int64, _ time.Duration) (map[int64]int, error) { - return nil, nil -} -func (m *mockGatewayCacheForGemini) GetAccountAffinityClients(_ context.Context, _ int64, _ time.Duration) ([]AffinityClientInfo, error) { - return nil, nil -} // TestGeminiMessagesCompatService_SelectAccountForModelWithExclusions_GeminiPlatform 测试 Gemini 单平台选择 func TestGeminiMessagesCompatService_SelectAccountForModelWithExclusions_GeminiPlatform(t *testing.T) { diff --git a/backend/internal/service/openai_gateway_service_test.go b/backend/internal/service/openai_gateway_service_test.go index 7b7b6da415..7e53c8996e 100644 --- a/backend/internal/service/openai_gateway_service_test.go +++ b/backend/internal/service/openai_gateway_service_test.go @@ -274,15 +274,6 @@ func (c *stubGatewayCache) UpdateClientAffinity(_ context.Context, _ int64, _ st func (c *stubGatewayCache) RemoveClientAffinity(_ context.Context, _ int64, _ string, _ int64) error { return nil } -func (c *stubGatewayCache) GetAccountAffinityCount(_ context.Context, _ int64, _ time.Duration) (int, error) { - return 0, nil -} -func (c *stubGatewayCache) GetAccountAffinityCountBatch(_ context.Context, _ []int64, _ time.Duration) (map[int64]int, error) { - return nil, nil -} -func (c *stubGatewayCache) GetAccountAffinityClients(_ context.Context, _ int64, _ time.Duration) ([]AffinityClientInfo, error) { - return nil, nil -} func TestOpenAISelectAccountWithLoadAwareness_FiltersUnschedulable(t *testing.T) { now := time.Now() diff --git a/backend/internal/service/openai_ws_state_store_test.go b/backend/internal/service/openai_ws_state_store_test.go index 273bfadddb..6f77f64356 100644 --- a/backend/internal/service/openai_ws_state_store_test.go +++ b/backend/internal/service/openai_ws_state_store_test.go @@ -202,15 +202,6 @@ func (c *openAIWSStateStoreTimeoutProbeCache) UpdateClientAffinity(_ context.Con func (c *openAIWSStateStoreTimeoutProbeCache) RemoveClientAffinity(_ context.Context, _ int64, _ string, _ int64) error { return nil } -func (c *openAIWSStateStoreTimeoutProbeCache) GetAccountAffinityCount(_ context.Context, _ int64, _ time.Duration) (int, error) { - return 0, nil -} -func (c *openAIWSStateStoreTimeoutProbeCache) GetAccountAffinityCountBatch(_ context.Context, _ []int64, _ time.Duration) (map[int64]int, error) { - return nil, nil -} -func (c *openAIWSStateStoreTimeoutProbeCache) GetAccountAffinityClients(_ context.Context, _ int64, _ time.Duration) ([]AffinityClientInfo, error) { - return nil, nil -} func TestOpenAIWSStateStore_RedisOpsUseShortTimeout(t *testing.T) { probe := &openAIWSStateStoreTimeoutProbeCache{} diff --git a/backend/internal/testutil/stubs.go b/backend/internal/testutil/stubs.go index 8c6f54dd07..669372ef51 100644 --- a/backend/internal/testutil/stubs.go +++ b/backend/internal/testutil/stubs.go @@ -106,15 +106,6 @@ func (c StubGatewayCache) UpdateClientAffinity(_ context.Context, _ int64, _ str func (c StubGatewayCache) RemoveClientAffinity(_ context.Context, _ int64, _ string, _ int64) error { return nil } -func (c StubGatewayCache) GetAccountAffinityCount(_ context.Context, _ int64, _ time.Duration) (int, error) { - return 0, nil -} -func (c StubGatewayCache) GetAccountAffinityCountBatch(_ context.Context, _ []int64, _ time.Duration) (map[int64]int, error) { - return nil, nil -} -func (c StubGatewayCache) GetAccountAffinityClients(_ context.Context, _ int64, _ time.Duration) ([]service.AffinityClientInfo, error) { - return nil, nil -} // ============================================================ // StubSessionLimitCache — service.SessionLimitCache 的空实现 diff --git a/frontend/src/components/account/AccountStatusIndicator.vue b/frontend/src/components/account/AccountStatusIndicator.vue index 4465cff482..728b310ccc 100644 --- a/frontend/src/components/account/AccountStatusIndicator.vue +++ b/frontend/src/components/account/AccountStatusIndicator.vue @@ -1,29 +1,5 @@