From c0925ea75cd43d56dcb9276d868c0197a9e14e12 Mon Sep 17 00:00:00 2001 From: Jaanus Sellin Date: Thu, 12 Dec 2024 15:06:33 +0200 Subject: [PATCH] fix: do not initialize cache when flag is off (#8969) This feature is still in early alpha. We do not want to populate any cache on startup. We might not want to do it ever. --- .../cache/client-feature-toggle-cache.ts | 11 +++++++++-- .../cache/createClientFeatureToggleCache.ts | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/lib/features/client-feature-toggles/cache/client-feature-toggle-cache.ts b/src/lib/features/client-feature-toggles/cache/client-feature-toggle-cache.ts index 4c9ca310fd..713e8f39e2 100644 --- a/src/lib/features/client-feature-toggles/cache/client-feature-toggle-cache.ts +++ b/src/lib/features/client-feature-toggles/cache/client-feature-toggle-cache.ts @@ -3,6 +3,7 @@ import type { IFeatureToggleClient, IFeatureToggleClientStore, IFeatureToggleQuery, + IFlagResolver, } from '../../../types'; import type { FeatureConfigurationClient } from '../../feature-toggle/types/feature-toggle-strategies-store-type'; import type ConfigurationRevisionService from '../../feature-toggle/configuration-revision-service'; @@ -99,19 +100,23 @@ export class ClientFeatureToggleCache { private interval: NodeJS.Timer; + private flagResolver: IFlagResolver; + private configurationRevisionService: ConfigurationRevisionService; constructor( clientFeatureToggleStore: IFeatureToggleClientStore, eventStore: IEventStore, configurationRevisionService: ConfigurationRevisionService, + flagResolver: IFlagResolver, ) { this.eventStore = eventStore; this.configurationRevisionService = configurationRevisionService; this.clientFeatureToggleStore = clientFeatureToggleStore; + this.flagResolver = flagResolver; this.onUpdateRevisionEvent = this.onUpdateRevisionEvent.bind(this); - this.initCache(); + // this.initCache(); TODO: we dont want to initialize cache on startup, but ondemand in future? this.configurationRevisionService.on( UPDATE_REVISION, this.onUpdateRevisionEvent, @@ -158,7 +163,9 @@ export class ClientFeatureToggleCache { } private async onUpdateRevisionEvent() { - await this.pollEvents(); + if (this.flagResolver.isEnabled('deltaApi')) { + await this.pollEvents(); + } } public async pollEvents() { diff --git a/src/lib/features/client-feature-toggles/cache/createClientFeatureToggleCache.ts b/src/lib/features/client-feature-toggles/cache/createClientFeatureToggleCache.ts index e315594346..b49c213616 100644 --- a/src/lib/features/client-feature-toggles/cache/createClientFeatureToggleCache.ts +++ b/src/lib/features/client-feature-toggles/cache/createClientFeatureToggleCache.ts @@ -27,6 +27,7 @@ export const createClientFeatureToggleCache = ( featureToggleClientStore, eventStore, configurationRevisionService, + flagResolver, ); return clientFeatureToggleCache;