From e619ca386eef8962d8b8edea431ff837a361fc45 Mon Sep 17 00:00:00 2001 From: Ritel-T Date: Tue, 1 Sep 2026 04:31:36 +0900 Subject: [PATCH] Carry free Fast through auth snapshots --- backend/internal/service/api_key_auth_cache.go | 1 + backend/internal/service/api_key_auth_cache_impl.go | 4 +++- .../internal/service/api_key_auth_cache_openai_fast_test.go | 5 +++-- backend/internal/service/api_key_auth_cache_profit_test.go | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/backend/internal/service/api_key_auth_cache.go b/backend/internal/service/api_key_auth_cache.go index 0bdbfc8293..be08213d17 100644 --- a/backend/internal/service/api_key_auth_cache.go +++ b/backend/internal/service/api_key_auth_cache.go @@ -104,6 +104,7 @@ type APIKeyAuthGroupSnapshot struct { AllowMessagesDispatch bool `json:"allow_messages_dispatch"` AllowLive bool `json:"allow_live"` ForceOpenAIFast bool `json:"force_openai_fast"` + FreeOpenAIFast bool `json:"free_openai_fast"` DefaultMappedModel string `json:"default_mapped_model,omitempty"` MessagesDispatchModelConfig OpenAIMessagesDispatchModelConfig `json:"messages_dispatch_model_config,omitempty"` ModelsListConfig GroupModelsListConfig `json:"models_list_config,omitempty"` diff --git a/backend/internal/service/api_key_auth_cache_impl.go b/backend/internal/service/api_key_auth_cache_impl.go index f267a3fe89..800c888f68 100644 --- a/backend/internal/service/api_key_auth_cache_impl.go +++ b/backend/internal/service/api_key_auth_cache_impl.go @@ -14,7 +14,7 @@ import ( "github.com/dgraph-io/ristretto" ) -const apiKeyAuthSnapshotVersion = 21 // v21: group force_openai_fast field +const apiKeyAuthSnapshotVersion = 22 // v22: group free_openai_fast field type apiKeyAuthCacheConfig struct { l1Size int @@ -419,6 +419,7 @@ func (s *APIKeyService) snapshotFromAPIKey(ctx context.Context, apiKey *APIKey) AllowMessagesDispatch: apiKey.Group.AllowMessagesDispatch, AllowLive: apiKey.Group.AllowLive, ForceOpenAIFast: apiKey.Group.ForceOpenAIFast, + FreeOpenAIFast: apiKey.Group.FreeOpenAIFast, DefaultMappedModel: apiKey.Group.DefaultMappedModel, MessagesDispatchModelConfig: apiKey.Group.MessagesDispatchModelConfig, ModelsListConfig: apiKey.Group.ModelsListConfig, @@ -518,6 +519,7 @@ func (s *APIKeyService) snapshotToAPIKey(key string, snapshot *APIKeyAuthSnapsho AllowMessagesDispatch: snapshot.Group.AllowMessagesDispatch, AllowLive: snapshot.Group.AllowLive, ForceOpenAIFast: snapshot.Group.ForceOpenAIFast, + FreeOpenAIFast: snapshot.Group.FreeOpenAIFast, DefaultMappedModel: snapshot.Group.DefaultMappedModel, MessagesDispatchModelConfig: snapshot.Group.MessagesDispatchModelConfig, ModelsListConfig: snapshot.Group.ModelsListConfig, diff --git a/backend/internal/service/api_key_auth_cache_openai_fast_test.go b/backend/internal/service/api_key_auth_cache_openai_fast_test.go index 18a1d3ca9d..07e906e4e7 100644 --- a/backend/internal/service/api_key_auth_cache_openai_fast_test.go +++ b/backend/internal/service/api_key_auth_cache_openai_fast_test.go @@ -15,7 +15,7 @@ func TestAPIKeyAuthSnapshotGroupForceOpenAIFastRoundtrip(t *testing.T) { User: &User{ID: 40, Status: StatusActive}, Group: &Group{ ID: groupID, Name: "fast-roundtrip", Platform: PlatformOpenAI, Status: StatusActive, - Hydrated: true, ForceOpenAIFast: true, + Hydrated: true, ForceOpenAIFast: true, FreeOpenAIFast: true, }, } svc := &APIKeyService{} @@ -31,5 +31,6 @@ func TestAPIKeyAuthSnapshotGroupForceOpenAIFastRoundtrip(t *testing.T) { require.NotNil(t, materialized.Group) require.True(t, materialized.Group.Hydrated) require.True(t, materialized.Group.ForceOpenAIFast) - require.Equal(t, 21, cached.Snapshot.Version) + require.True(t, materialized.Group.FreeOpenAIFast) + require.Equal(t, 22, cached.Snapshot.Version) } diff --git a/backend/internal/service/api_key_auth_cache_profit_test.go b/backend/internal/service/api_key_auth_cache_profit_test.go index d69d21d869..51347e0eab 100644 --- a/backend/internal/service/api_key_auth_cache_profit_test.go +++ b/backend/internal/service/api_key_auth_cache_profit_test.go @@ -53,7 +53,7 @@ func TestAPIKeyAuthSnapshotProfitControlRoundtrip(t *testing.T) { snapshot := svc.snapshotFromAPIKey(context.Background(), apiKey) require.NotNil(t, snapshot) require.Equal(t, apiKeyAuthSnapshotVersion, snapshot.Version) - require.Equal(t, 21, snapshot.Version, "v21 起认证快照携带分组 Fast 强制开关") + require.Equal(t, 22, snapshot.Version, "v22 起认证快照携带分组免费 Fast 开关") // 模拟 L2 缓存的完整 JSON 往返(与 apiKeyCache.SetAuthCache/GetAuthCache 同构)。 payload, err := json.Marshal(&APIKeyAuthCacheEntry{Snapshot: snapshot})