From 4cf9f16db5419154eb0bf411003a1277970bef3e Mon Sep 17 00:00:00 2001 From: Gitar Date: Wed, 2 Oct 2024 11:53:56 +0000 Subject: [PATCH] [Gitar] Updating TypeScript files --- src/lib/db/user-store.ts | 32 +++++++++---------- .../onboarding/onboarding-read-model.test.ts | 2 +- .../onboarding/onboarding-service.e2e.test.ts | 11 +++---- .../features/onboarding/onboarding-service.ts | 4 --- src/lib/metrics.ts | 8 ++--- src/lib/types/experimental.ts | 5 --- src/server-dev.ts | 1 - src/test/e2e/stores/user-store.e2e.test.ts | 2 +- 8 files changed, 23 insertions(+), 42 deletions(-) diff --git a/src/lib/db/user-store.ts b/src/lib/db/user-store.ts index e6a783c564f6..fb3d749ba5eb 100644 --- a/src/lib/db/user-store.ts +++ b/src/lib/db/user-store.ts @@ -240,23 +240,21 @@ class UserStore implements IUserStore { let firstLoginOrder = 0; - if (this.flagResolver.isEnabled('onboardingMetrics')) { - const existingUser = - await this.buildSelectUser(user).first('first_seen_at'); - - if (!existingUser.first_seen_at) { - const countEarlierUsers = await this.db(TABLE) - .whereNotNull('first_seen_at') - .andWhere('first_seen_at', '<', currentDate) - .count('*') - .then((res) => Number(res[0].count)); - - firstLoginOrder = countEarlierUsers; - - await updateQuery.update({ - first_seen_at: currentDate, - }); - } + const existingUser = + await this.buildSelectUser(user).first('first_seen_at'); + + if (!existingUser.first_seen_at) { + const countEarlierUsers = await this.db(TABLE) + .whereNotNull('first_seen_at') + .andWhere('first_seen_at', '<', currentDate) + .count('*') + .then((res) => Number(res[0].count)); + + firstLoginOrder = countEarlierUsers; + + await updateQuery.update({ + first_seen_at: currentDate, + }); } await updateQuery; diff --git a/src/lib/features/onboarding/onboarding-read-model.test.ts b/src/lib/features/onboarding/onboarding-read-model.test.ts index 2b9d1c560288..c51e2c0b0733 100644 --- a/src/lib/features/onboarding/onboarding-read-model.test.ts +++ b/src/lib/features/onboarding/onboarding-read-model.test.ts @@ -16,7 +16,7 @@ let lastSeenStore: ILastSeenStore; beforeAll(async () => { db = await dbInit('onboarding_read_model', getLogger, { - experimental: { flags: { onboardingMetrics: true } }, + experimental: { flags: {} }, }); onboardingReadModel = db.stores.onboardingReadModel; onBoardingStore = db.stores.onboardingStore; diff --git a/src/lib/features/onboarding/onboarding-service.e2e.test.ts b/src/lib/features/onboarding/onboarding-service.e2e.test.ts index cc4ab8382d1c..1e4bcb7b3ee1 100644 --- a/src/lib/features/onboarding/onboarding-service.e2e.test.ts +++ b/src/lib/features/onboarding/onboarding-service.e2e.test.ts @@ -17,7 +17,7 @@ let onboardingReadModel: IOnboardingReadModel; beforeAll(async () => { db = await dbInit('onboarding_store', getLogger); const config = createTestConfig({ - experimental: { flags: { onboardingMetrics: true } }, + experimental: { flags: {} }, }); stores = db.stores; eventBus = config.eventBus; @@ -41,8 +41,7 @@ beforeEach(async () => { test('Default project should take first user created instead of project created as start time', async () => { jest.useFakeTimers(); jest.setSystemTime(new Date()); - const { userStore, featureToggleStore, projectStore, projectReadModel } = - stores; + const { userStore, featureToggleStore, projectStore } = stores; // default projects are created in advance and should be ignored await projectStore.create({ id: 'default', name: 'irrelevant' }); @@ -106,8 +105,7 @@ test('Ignore system user in onboarding events', async () => { test('Storing onboarding events', async () => { jest.useFakeTimers(); jest.setSystemTime(new Date()); - const { userStore, featureToggleStore, projectStore, projectReadModel } = - stores; + const { userStore, featureToggleStore, projectStore } = stores; const user = await userStore.insert({}); await projectStore.create({ id: 'test_project', name: 'irrelevant' }); await featureToggleStore.create('test_project', { @@ -172,8 +170,7 @@ const reachedOnboardingEvents = (count: number) => { test('Reacting to events', async () => { jest.useFakeTimers(); jest.setSystemTime(new Date()); - const { userStore, featureToggleStore, projectStore, projectReadModel } = - stores; + const { userStore, featureToggleStore, projectStore } = stores; const user = await userStore.insert({}); await projectStore.create({ id: 'test_project', name: 'irrelevant' }); await featureToggleStore.create('test_project', { diff --git a/src/lib/features/onboarding/onboarding-service.ts b/src/lib/features/onboarding/onboarding-service.ts index a5394653d07a..7afdefddd9eb 100644 --- a/src/lib/features/onboarding/onboarding-service.ts +++ b/src/lib/features/onboarding/onboarding-service.ts @@ -56,8 +56,6 @@ export class OnboardingService { listen() { this.eventBus.on(USER_LOGIN, async (event: { loginOrder: number }) => { - if (!this.flagResolver.isEnabled('onboardingMetrics')) return; - if (event.loginOrder === 0) { await this.insert({ type: 'first-user-login' }); } @@ -68,8 +66,6 @@ export class OnboardingService { } }); this.eventBus.on(STAGE_ENTERED, async (stage: NewStage) => { - if (!this.flagResolver.isEnabled('onboardingMetrics')) return; - if (stage.stage === 'initial') { await this.insert({ type: 'flag-created', diff --git a/src/lib/metrics.ts b/src/lib/metrics.ts index d724fb44ab7b..27ba80f32720 100644 --- a/src/lib/metrics.ts +++ b/src/lib/metrics.ts @@ -421,12 +421,8 @@ export default class MetricsMonitor { 1, ), stores.apiTokenStore.countDeprecatedTokens(), - flagResolver.isEnabled('onboardingMetrics') - ? stores.onboardingReadModel.getInstanceOnboardingMetrics() - : Promise.resolve({}), - flagResolver.isEnabled('onboardingMetrics') - ? stores.onboardingReadModel.getProjectsOnboardingMetrics() - : Promise.resolve([]), + stores.onboardingReadModel.getInstanceOnboardingMetrics(), + stores.onboardingReadModel.getProjectsOnboardingMetrics(), ]); featureFlagsTotal.reset(); diff --git a/src/lib/types/experimental.ts b/src/lib/types/experimental.ts index 9df11056bc8d..2e492710ae6e 100644 --- a/src/lib/types/experimental.ts +++ b/src/lib/types/experimental.ts @@ -56,7 +56,6 @@ export type IFlagKey = | 'removeUnsafeInlineStyleSrc' | 'originMiddleware' | 'addonUsageMetrics' - | 'onboardingMetrics' | 'onboardingUI' | 'projectRoleAssignment' | 'eventTimeline' @@ -277,10 +276,6 @@ const flags: IFlags = { process.env.UNLEASH_EXPERIMENTAL_ADDON_USAGE_METRICS, false, ), - onboardingMetrics: parseEnvVarBoolean( - process.env.UNLEASH_EXPERIMENTAL_ONBOARDING_METRICS, - false, - ), onboardingUI: parseEnvVarBoolean( process.env.UNLEASH_EXPERIMENTAL_ONBOARDING_UI, false, diff --git a/src/server-dev.ts b/src/server-dev.ts index f702cdbcc2ef..698e28baac57 100644 --- a/src/server-dev.ts +++ b/src/server-dev.ts @@ -52,7 +52,6 @@ process.nextTick(async () => { extendedMetrics: true, originMiddleware: true, addonUsageMetrics: true, - onboardingMetrics: true, onboardingUI: true, personalDashboardUI: true, }, diff --git a/src/test/e2e/stores/user-store.e2e.test.ts b/src/test/e2e/stores/user-store.e2e.test.ts index dda39b36e491..93f587fa9713 100644 --- a/src/test/e2e/stores/user-store.e2e.test.ts +++ b/src/test/e2e/stores/user-store.e2e.test.ts @@ -8,7 +8,7 @@ let db: ITestDb; beforeAll(async () => { db = await dbInit('user_store_serial', getLogger, { - experimental: { flags: { onboardingMetrics: true } }, + experimental: { flags: {} }, }); stores = db.stores; });