Skip to content

Commit

Permalink
refactor(core): optimize init
Browse files Browse the repository at this point in the history
  • Loading branch information
gao-sun committed May 6, 2024
1 parent c1c8410 commit 268ca41
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions packages/core/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { appInsights } from '@logto/app-insights/node';

Check warning on line 1 in packages/core/src/main.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/main.ts#L1

Added line #L1 was not covered by tests
import { ConsoleLog } from '@logto/shared';
import { trySafe } from '@silverhand/essentials';
import chalk from 'chalk';
import Koa from 'koa';

import initApp from './app/init.js';

Check warning on line 7 in packages/core/src/main.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/main.ts#L7

Added line #L7 was not covered by tests
import { redisCache } from './caches/index.js';
import { checkAlterationState } from './env-set/check-alteration-state.js';
import { EnvSet } from './env-set/index.js';
Expand All @@ -11,7 +13,6 @@ import SystemContext from './tenants/SystemContext.js';
import { checkRowLevelSecurity, tenantPool } from './tenants/index.js';
import { loadConnectorFactories } from './utils/connectors/index.js';

const { appInsights } = await import('@logto/app-insights/node');
const consoleLog = new ConsoleLog(chalk.magenta('index'));

if (await appInsights.setup('core')) {
Expand All @@ -33,8 +34,6 @@ try {
SystemContext.shared.loadProviderConfigs(sharedAdminPool),
]);

// Import last until init completed
const { default: initApp } = await import('./app/init.js');
await initApp(app);
} catch (error: unknown) {
consoleLog.error('Error while initializing app:');
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/tenants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class TenantPool {
// Otherwise, create a new tenant instance and store in LRU cache, using the code below.
}

consoleLog.info('Init tenant:', tenantId, customDomain);
consoleLog.info('Init tenant:', tenantId, 'Custom domain:', customDomain);

Check warning on line 34 in packages/core/src/tenants/index.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/tenants/index.ts#L34

Added line #L34 was not covered by tests
const newTenantPromise = Tenant.create({ id: tenantId, redisCache, customDomain });
this.cache.set(cacheKey, newTenantPromise);

Expand Down

0 comments on commit 268ca41

Please sign in to comment.