1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

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.
This commit is contained in:
Jaanus Sellin 2024-12-12 15:06:33 +02:00 committed by GitHub
parent de7b95a691
commit c0925ea75c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 2 deletions

View File

@ -3,6 +3,7 @@ import type {
IFeatureToggleClient, IFeatureToggleClient,
IFeatureToggleClientStore, IFeatureToggleClientStore,
IFeatureToggleQuery, IFeatureToggleQuery,
IFlagResolver,
} from '../../../types'; } from '../../../types';
import type { FeatureConfigurationClient } from '../../feature-toggle/types/feature-toggle-strategies-store-type'; import type { FeatureConfigurationClient } from '../../feature-toggle/types/feature-toggle-strategies-store-type';
import type ConfigurationRevisionService from '../../feature-toggle/configuration-revision-service'; import type ConfigurationRevisionService from '../../feature-toggle/configuration-revision-service';
@ -99,19 +100,23 @@ export class ClientFeatureToggleCache {
private interval: NodeJS.Timer; private interval: NodeJS.Timer;
private flagResolver: IFlagResolver;
private configurationRevisionService: ConfigurationRevisionService; private configurationRevisionService: ConfigurationRevisionService;
constructor( constructor(
clientFeatureToggleStore: IFeatureToggleClientStore, clientFeatureToggleStore: IFeatureToggleClientStore,
eventStore: IEventStore, eventStore: IEventStore,
configurationRevisionService: ConfigurationRevisionService, configurationRevisionService: ConfigurationRevisionService,
flagResolver: IFlagResolver,
) { ) {
this.eventStore = eventStore; this.eventStore = eventStore;
this.configurationRevisionService = configurationRevisionService; this.configurationRevisionService = configurationRevisionService;
this.clientFeatureToggleStore = clientFeatureToggleStore; this.clientFeatureToggleStore = clientFeatureToggleStore;
this.flagResolver = flagResolver;
this.onUpdateRevisionEvent = this.onUpdateRevisionEvent.bind(this); 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( this.configurationRevisionService.on(
UPDATE_REVISION, UPDATE_REVISION,
this.onUpdateRevisionEvent, this.onUpdateRevisionEvent,
@ -158,7 +163,9 @@ export class ClientFeatureToggleCache {
} }
private async onUpdateRevisionEvent() { private async onUpdateRevisionEvent() {
await this.pollEvents(); if (this.flagResolver.isEnabled('deltaApi')) {
await this.pollEvents();
}
} }
public async pollEvents() { public async pollEvents() {

View File

@ -27,6 +27,7 @@ export const createClientFeatureToggleCache = (
featureToggleClientStore, featureToggleClientStore,
eventStore, eventStore,
configurationRevisionService, configurationRevisionService,
flagResolver,
); );
return clientFeatureToggleCache; return clientFeatureToggleCache;