mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-31 00:16:47 +01:00
8aec4a02cb
In a new fresh Unleash instance with cache enabled this can cause feature toggles to never get updated. We saw in our client that the ETag was ETag: "60e35fba:null" Which looked incorrect for us. I also did manual testing and if the andWhere had a value of largerThan higher than whatever the id was then we would get back { max: null }. This should fix that issue.
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import { EventEmitter } from 'stream';
|
|
import { Logger } from '../../logger';
|
|
import { IEventStore, IUnleashConfig, IUnleashStores } from '../../types';
|
|
|
|
export const UPDATE_REVISION = 'UPDATE_REVISION';
|
|
|
|
export default class ConfigurationRevisionService extends EventEmitter {
|
|
private logger: Logger;
|
|
|
|
private eventStore: IEventStore;
|
|
|
|
private revisionId: number;
|
|
|
|
constructor(
|
|
{ eventStore }: Pick<IUnleashStores, 'eventStore'>,
|
|
{ getLogger }: Pick<IUnleashConfig, 'getLogger'>,
|
|
) {
|
|
super();
|
|
this.logger = getLogger('configuration-revision-service.ts');
|
|
this.eventStore = eventStore;
|
|
this.revisionId = 0;
|
|
}
|
|
|
|
async getMaxRevisionId(): Promise<number> {
|
|
if (this.revisionId > 0) {
|
|
return this.revisionId;
|
|
} else {
|
|
return this.updateMaxRevisionId();
|
|
}
|
|
}
|
|
|
|
async updateMaxRevisionId(): Promise<number> {
|
|
const revisionId = await this.eventStore.getMaxRevisionId(
|
|
this.revisionId,
|
|
);
|
|
if (this.revisionId !== revisionId) {
|
|
this.logger.debug(
|
|
'Updating feature configuration with new revision Id',
|
|
revisionId,
|
|
);
|
|
this.emit(UPDATE_REVISION, revisionId);
|
|
this.revisionId = revisionId;
|
|
}
|
|
|
|
return this.revisionId;
|
|
}
|
|
}
|