From 486c1740049258efefb9bcc95740c8994f1f32be Mon Sep 17 00:00:00 2001 From: Kamil Zegier Date: Fri, 29 Sep 2023 14:59:28 +0200 Subject: [PATCH] fix: Add condition for getting max revision id from store (#4549) ## About the changes In our staging setup, we create ad-hoc environments and import Unleash state from production. After unleash is deployed on such environment, the import job kicks in and feeds Unleash instance with feature flags from production. Between Unleash being up and running and the import job running, some applications start polling Unleash. They get an empty feature toggle list with `meta.revisionId=0`. Then apps use this as part of `eTag` header in subsequent requests. Even though after import Unleash server finally has toggles to serve, it doesn't because it calculates _max revision id_ based on toggle updates (not null `feature_name` column in query) or `SEGMENT_UPDATED`. This change adds an extra condition to query so feature toggles import is considered something that should invalidate the cache. --- src/lib/db/event-store.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lib/db/event-store.ts b/src/lib/db/event-store.ts index ae51d52677..37c303be1b 100644 --- a/src/lib/db/event-store.ts +++ b/src/lib/db/event-store.ts @@ -2,6 +2,8 @@ import { IEvent, IBaseEvent, SEGMENT_UPDATED, + FEATURE_IMPORT, + FEATURES_IMPORTED, IEventType, } from '../types/events'; import { LogProvider, Logger } from '../logger'; @@ -158,7 +160,11 @@ class EventStore implements IEventStore { .where((builder) => builder .whereNotNull('feature_name') - .orWhere('type', SEGMENT_UPDATED), + .orWhereIn('type', [ + SEGMENT_UPDATED, + FEATURE_IMPORT, + FEATURES_IMPORTED, + ]), ) .andWhere('id', '>=', largerThan) .first();