mirror of
https://github.com/Unleash/unleash.git
synced 2025-03-18 00:19:49 +01:00
fix: now hydration event is being returned if revision does not exist in cache (#9203)
Now when customer is coming with revision ID that does not exist in cache, we return hydration.
This commit is contained in:
parent
96dac84880
commit
d8a47ce39d
@ -270,3 +270,54 @@ test('should get segment updated and removed events', async () => {
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
test('should return hydration if revision not in cache', async () => {
|
||||
await app.createFeature('base_feature');
|
||||
await syncRevisions();
|
||||
const { body, headers } = await app.request
|
||||
.get('/api/client/delta')
|
||||
.expect(200);
|
||||
const etag = headers.etag;
|
||||
|
||||
expect(body).toMatchObject({
|
||||
events: [
|
||||
{
|
||||
type: DELTA_EVENT_TYPES.HYDRATION,
|
||||
features: [
|
||||
{
|
||||
name: 'base_feature',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
await app.createFeature('not_important1');
|
||||
await syncRevisions();
|
||||
|
||||
const { body: deltaBody } = await app.request
|
||||
.get('/api/client/delta')
|
||||
.set('If-None-Match', etag)
|
||||
.expect(200);
|
||||
|
||||
expect(deltaBody).toMatchObject({
|
||||
events: [
|
||||
{
|
||||
type: DELTA_EVENT_TYPES.FEATURE_UPDATED,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const { body: rehydrationBody } = await app.request
|
||||
.get('/api/client/delta')
|
||||
.set('If-None-Match', '1')
|
||||
.expect(200);
|
||||
|
||||
expect(rehydrationBody).toMatchObject({
|
||||
events: [
|
||||
{
|
||||
type: DELTA_EVENT_TYPES.HYDRATION,
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
@ -154,8 +154,12 @@ export class ClientFeatureToggleDelta {
|
||||
if (requiredRevisionId >= this.currentRevisionId) {
|
||||
return undefined;
|
||||
}
|
||||
if (requiredRevisionId === 0) {
|
||||
const hydrationEvent = this.delta[environment].getHydrationEvent();
|
||||
const delta = this.delta[environment];
|
||||
if (
|
||||
requiredRevisionId === 0 ||
|
||||
delta.isMissingRevision(requiredRevisionId)
|
||||
) {
|
||||
const hydrationEvent = delta.getHydrationEvent();
|
||||
const filteredEvent = filterHydrationEventByQuery(
|
||||
hydrationEvent,
|
||||
projects,
|
||||
@ -168,7 +172,7 @@ export class ClientFeatureToggleDelta {
|
||||
|
||||
return Promise.resolve(response);
|
||||
} else {
|
||||
const environmentEvents = this.delta[environment].getEvents();
|
||||
const environmentEvents = delta.getEvents();
|
||||
const events = filterEventsByQuery(
|
||||
environmentEvents,
|
||||
requiredRevisionId,
|
||||
@ -299,8 +303,7 @@ export class ClientFeatureToggleDelta {
|
||||
});
|
||||
}
|
||||
|
||||
public async initEnvironmentDelta(environment: string) {
|
||||
// Todo: replace with method that gets all features for an environment
|
||||
private async initEnvironmentDelta(environment: string) {
|
||||
const baseFeatures = await this.getClientFeatures({
|
||||
environment,
|
||||
});
|
||||
|
@ -12,6 +12,22 @@ export class DeltaCache {
|
||||
constructor(hydrationEvent: DeltaHydrationEvent, maxLength: number = 20) {
|
||||
this.hydrationEvent = hydrationEvent;
|
||||
this.maxLength = maxLength;
|
||||
|
||||
this.addBaseEventFromHydration(hydrationEvent);
|
||||
}
|
||||
|
||||
private addBaseEventFromHydration(
|
||||
hydrationEvent: DeltaHydrationEvent,
|
||||
): void {
|
||||
const lastFeature =
|
||||
hydrationEvent.features[hydrationEvent.features.length - 1];
|
||||
this.addEvents([
|
||||
{
|
||||
eventId: hydrationEvent.eventId,
|
||||
type: 'feature-updated',
|
||||
feature: lastFeature,
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
public addEvents(events: DeltaEvent[]): void {
|
||||
@ -27,6 +43,10 @@ export class DeltaCache {
|
||||
return this.events;
|
||||
}
|
||||
|
||||
public isMissingRevision(revisionId: number): boolean {
|
||||
return !this.events.some((event) => event.eventId === revisionId);
|
||||
}
|
||||
|
||||
public getHydrationEvent(): DeltaHydrationEvent {
|
||||
return this.hydrationEvent;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user