Improve performance twenty orm (#6691)

## Context

As we grow, the messaging scripts are experiencing performance issues
forcing us to temporarily disable them on the cloud.
While investigating the performance, I have noticed that generating the
entity schema (for twentyORM) in the repository is taking ~500ms locally
on my Mac M2 so likely more on pods. Caching the entitySchema then!

I'm also clarifying naming around schemaVersion and cacheVersions ==>
both are renamed workspaceMetadataVersion and migrated to the workspace
table (the workspaceCacheVersion table is dropped).
This commit is contained in:
Charles Bochet
2024-08-20 19:42:02 +02:00
committed by GitHub
parent 3ae89d15de
commit 17a1760afd
80 changed files with 583 additions and 468 deletions

View File

@ -1,14 +1,13 @@
import { InjectRepository } from '@nestjs/typeorm';
import { Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Command, CommandRunner, Option } from 'nest-commander';
import { In, Repository } from 'typeorm';
import { WorkspaceService } from 'src/engine/core-modules/workspace/services/workspace.service';
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
import { DataSourceService } from 'src/engine/metadata-modules/data-source/data-source.service';
import { getDryRunLogHeader } from 'src/utils/get-dry-run-log-header';
import { WorkspaceService } from 'src/engine/core-modules/workspace/services/workspace.service';
import { LoadServiceWithWorkspaceContext } from 'src/engine/twenty-orm/context/load-service-with-workspace.context';
type DeleteWorkspacesCommandOptions = {
dryRun?: boolean;
@ -24,7 +23,6 @@ export class DeleteWorkspacesCommand extends CommandRunner {
constructor(
private readonly workspaceService: WorkspaceService,
private readonly loadServiceWithWorkspaceContext: LoadServiceWithWorkspaceContext,
@InjectRepository(Workspace, 'core')
private readonly workspaceRepository: Repository<Workspace>,
private readonly dataSourceService: DataSourceService,
@ -81,15 +79,15 @@ export class DeleteWorkspacesCommand extends CommandRunner {
workspace.id
} name: '${workspace.displayName}'`,
);
const workspaceServiceInstance =
await this.loadServiceWithWorkspaceContext.load(
this.workspaceService,
workspace.id,
);
// const workspaceServiceInstance =
// await this.loadServiceWithWorkspaceContext.load(
// this.workspaceService,
// workspace.id,
// );
if (!options.dryRun) {
await workspaceServiceInstance.softDeleteWorkspace(workspace.id);
}
// if (!options.dryRun) {
// await workspaceServiceInstance.softDeleteWorkspace(workspace.id);
// }
}
}
}