Fix error messages on sign up (#10399)
In this PR: - adding logs to track workspace creation performance - refactor useIsWorkspaceSuspended to be more generic - only fetch favorites and views if workspace is Active to avoid error messages on sign up (workspace is not created yet)
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
|
||||
import { Repository } from 'typeorm';
|
||||
@ -32,6 +32,8 @@ import { WorkspaceSyncMetadataService } from 'src/engine/workspace-manager/works
|
||||
|
||||
@Injectable()
|
||||
export class WorkspaceManagerService {
|
||||
private readonly logger = new Logger(WorkspaceManagerService.name);
|
||||
|
||||
constructor(
|
||||
private readonly workspaceDataSourceService: WorkspaceDataSourceService,
|
||||
private readonly workspaceMigrationService: WorkspaceMigrationService,
|
||||
@ -63,11 +65,19 @@ export class WorkspaceManagerService {
|
||||
workspaceId: string;
|
||||
userId: string;
|
||||
}): Promise<void> {
|
||||
const schemaCreationStart = performance.now();
|
||||
const schemaName =
|
||||
await this.workspaceDataSourceService.createWorkspaceDBSchema(
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
const schemaCreationEnd = performance.now();
|
||||
|
||||
this.logger.log(
|
||||
`Schema creation took ${schemaCreationEnd - schemaCreationStart}ms`,
|
||||
);
|
||||
|
||||
const dataSourceMetadataCreationStart = performance.now();
|
||||
const dataSourceMetadata =
|
||||
await this.dataSourceService.createDataSourceMetadata(
|
||||
workspaceId,
|
||||
@ -79,6 +89,13 @@ export class WorkspaceManagerService {
|
||||
dataSourceId: dataSourceMetadata.id,
|
||||
});
|
||||
|
||||
const dataSourceMetadataCreationEnd = performance.now();
|
||||
|
||||
this.logger.log(
|
||||
`Metadata creation took ${dataSourceMetadataCreationEnd - dataSourceMetadataCreationStart}ms`,
|
||||
);
|
||||
|
||||
const permissionsEnabledStart = performance.now();
|
||||
const permissionsEnabled =
|
||||
await this.permissionsService.isPermissionsEnabled();
|
||||
|
||||
@ -86,10 +103,24 @@ export class WorkspaceManagerService {
|
||||
await this.initPermissions({ workspaceId, userId });
|
||||
}
|
||||
|
||||
const permissionsEnabledEnd = performance.now();
|
||||
|
||||
this.logger.log(
|
||||
`Permissions enabled took ${permissionsEnabledEnd - permissionsEnabledStart}ms`,
|
||||
);
|
||||
|
||||
const prefillStandardObjectsStart = performance.now();
|
||||
|
||||
await this.prefillWorkspaceWithStandardObjects(
|
||||
dataSourceMetadata,
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
const prefillStandardObjectsEnd = performance.now();
|
||||
|
||||
this.logger.log(
|
||||
`Prefill standard objects took ${prefillStandardObjectsEnd - prefillStandardObjectsStart}ms`,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -80,6 +80,8 @@ export class WorkspaceSyncMetadataService {
|
||||
this.logger.log('Syncing standard objects and fields metadata');
|
||||
|
||||
// 1 - Sync standard objects
|
||||
|
||||
const workspaceObjectMigrationsStart = performance.now();
|
||||
const workspaceObjectMigrations =
|
||||
await this.workspaceSyncObjectMetadataService.synchronize(
|
||||
context,
|
||||
@ -88,7 +90,14 @@ export class WorkspaceSyncMetadataService {
|
||||
workspaceFeatureFlagsMap,
|
||||
);
|
||||
|
||||
const workspaceObjectMigrationsEnd = performance.now();
|
||||
|
||||
this.logger.log(
|
||||
`Workspace object migrations took ${workspaceObjectMigrationsEnd - workspaceObjectMigrationsStart}ms`,
|
||||
);
|
||||
|
||||
// 2 - Sync standard fields on standard and custom objects
|
||||
const workspaceFieldMigrationsStart = performance.now();
|
||||
const workspaceFieldMigrations =
|
||||
await this.workspaceSyncFieldMetadataService.synchronize(
|
||||
context,
|
||||
@ -97,7 +106,14 @@ export class WorkspaceSyncMetadataService {
|
||||
workspaceFeatureFlagsMap,
|
||||
);
|
||||
|
||||
const workspaceFieldMigrationsEnd = performance.now();
|
||||
|
||||
this.logger.log(
|
||||
`Workspace field migrations took ${workspaceFieldMigrationsEnd - workspaceFieldMigrationsStart}ms`,
|
||||
);
|
||||
|
||||
// 3 - Sync standard relations on standard and custom objects
|
||||
const workspaceRelationMigrationsStart = performance.now();
|
||||
const workspaceRelationMigrations =
|
||||
await this.workspaceSyncRelationMetadataService.synchronize(
|
||||
context,
|
||||
@ -106,7 +122,14 @@ export class WorkspaceSyncMetadataService {
|
||||
workspaceFeatureFlagsMap,
|
||||
);
|
||||
|
||||
const workspaceRelationMigrationsEnd = performance.now();
|
||||
|
||||
this.logger.log(
|
||||
`Workspace relation migrations took ${workspaceRelationMigrationsEnd - workspaceRelationMigrationsStart}ms`,
|
||||
);
|
||||
|
||||
// 4 - Sync standard indexes on standard objects
|
||||
const workspaceIndexMigrationsStart = performance.now();
|
||||
const workspaceIndexMigrations =
|
||||
await this.workspaceSyncIndexMetadataService.synchronize(
|
||||
context,
|
||||
@ -115,7 +138,15 @@ export class WorkspaceSyncMetadataService {
|
||||
workspaceFeatureFlagsMap,
|
||||
);
|
||||
|
||||
const workspaceIndexMigrationsEnd = performance.now();
|
||||
|
||||
this.logger.log(
|
||||
`Workspace index migrations took ${workspaceIndexMigrationsEnd - workspaceIndexMigrationsStart}ms`,
|
||||
);
|
||||
|
||||
// 5 - Sync standard object metadata identifiers, does not need to return nor apply migrations
|
||||
const workspaceObjectMetadataIdentifiersStart = performance.now();
|
||||
|
||||
await this.workspaceSyncObjectMetadataIdentifiersService.synchronize(
|
||||
context,
|
||||
manager,
|
||||
@ -123,6 +154,14 @@ export class WorkspaceSyncMetadataService {
|
||||
workspaceFeatureFlagsMap,
|
||||
);
|
||||
|
||||
const workspaceObjectMetadataIdentifiersEnd = performance.now();
|
||||
|
||||
this.logger.log(
|
||||
`Workspace object metadata identifiers took ${workspaceObjectMetadataIdentifiersEnd - workspaceObjectMetadataIdentifiersStart}ms`,
|
||||
);
|
||||
|
||||
const workspaceMigrationsSaveStart = performance.now();
|
||||
|
||||
// Save workspace migrations into the database
|
||||
workspaceMigrations = await workspaceMigrationRepository.save([
|
||||
...workspaceObjectMigrations,
|
||||
@ -131,6 +170,12 @@ export class WorkspaceSyncMetadataService {
|
||||
...workspaceIndexMigrations,
|
||||
]);
|
||||
|
||||
const workspaceMigrationsSaveEnd = performance.now();
|
||||
|
||||
this.logger.log(
|
||||
`Workspace migrations save took ${workspaceMigrationsSaveEnd - workspaceMigrationsSaveStart}ms`,
|
||||
);
|
||||
|
||||
// If we're running a dry run, rollback the transaction and do not execute migrations
|
||||
if (!options.applyChanges) {
|
||||
this.logger.log('Running in dry run mode, rolling back transaction');
|
||||
@ -149,9 +194,16 @@ export class WorkspaceSyncMetadataService {
|
||||
|
||||
// Execute migrations
|
||||
this.logger.log('Executing pending migrations');
|
||||
const executeMigrationsStart = performance.now();
|
||||
|
||||
await this.workspaceMigrationRunnerService.executeMigrationFromPendingMigrations(
|
||||
context.workspaceId,
|
||||
);
|
||||
const executeMigrationsEnd = performance.now();
|
||||
|
||||
this.logger.log(
|
||||
`Execute migrations took ${executeMigrationsEnd - executeMigrationsStart}ms`,
|
||||
);
|
||||
} catch (error) {
|
||||
this.logger.error('Sync of standard objects failed with:', error);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user