Skip to content

Commit

Permalink
[Gitar] Updating TypeScript files
Browse files Browse the repository at this point in the history
  • Loading branch information
Gitar committed Oct 2, 2024
1 parent b975919 commit 4cf9f16
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 42 deletions.
32 changes: 15 additions & 17 deletions src/lib/db/user-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/features/onboarding/onboarding-read-model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 4 additions & 7 deletions src/lib/features/onboarding/onboarding-service.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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' });
Expand Down Expand Up @@ -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', {
Expand Down Expand Up @@ -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', {
Expand Down
4 changes: 0 additions & 4 deletions src/lib/features/onboarding/onboarding-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
}
Expand All @@ -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',
Expand Down
8 changes: 2 additions & 6 deletions src/lib/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 0 additions & 5 deletions src/lib/types/experimental.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export type IFlagKey =
| 'removeUnsafeInlineStyleSrc'
| 'originMiddleware'
| 'addonUsageMetrics'
| 'onboardingMetrics'
| 'onboardingUI'
| 'projectRoleAssignment'
| 'eventTimeline'
Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion src/server-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ process.nextTick(async () => {
extendedMetrics: true,
originMiddleware: true,
addonUsageMetrics: true,
onboardingMetrics: true,
onboardingUI: true,
personalDashboardUI: true,
},
Expand Down
2 changes: 1 addition & 1 deletion src/test/e2e/stores/user-store.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down

0 comments on commit 4cf9f16

Please sign in to comment.