Fix performance (#7131)

This commit is contained in:
Weiko 2024-09-18 21:15:30 +02:00 committed by GitHub
parent 41fe8f7fea
commit 210c336ccf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 26 additions and 35 deletions

View File

@ -40,11 +40,11 @@ export class GraphqlQueryParser {
const parsedFilter = graphqlQueryFilterParser.parse(recordFilter);
if (!('deletedAt' in this.fieldMetadataMap)) {
return parsedFilter;
}
// if (!('deletedAt' in this.fieldMetadataMap)) {
return parsedFilter;
// }
return this.addDefaultSoftDeleteCondition(parsedFilter);
// return this.addDefaultSoftDeleteCondition(parsedFilter);
}
private addDefaultSoftDeleteCondition(

View File

@ -65,6 +65,7 @@ export class GraphqlQueryFindOneResolverService {
where,
select,
})) as ObjectRecord;
const limit = QUERY_MAX_RECORDS;
if (!objectRecord) {

View File

@ -79,7 +79,6 @@ export class EntitySchemaColumnFactory {
nullable: fieldMetadata.isNullable,
createDate: key === 'createdAt',
updateDate: key === 'updatedAt',
deleteDate: key === 'deletedAt',
array: fieldMetadata.type === FieldMetadataType.MULTI_SELECT,
default: defaultValue,
};

View File

@ -4,7 +4,6 @@ import { EntitySchema } from 'typeorm';
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
import { DataSourceService } from 'src/engine/metadata-modules/data-source/data-source.service';
import { ObjectMetadataMap } from 'src/engine/metadata-modules/utils/generate-object-metadata-map.util';
import { WorkspaceMetadataCacheService } from 'src/engine/metadata-modules/workspace-metadata-cache/services/workspace-metadata-cache.service';
import { WorkspaceDataSource } from 'src/engine/twenty-orm/datasource/workspace.datasource';
import {
@ -36,13 +35,11 @@ export class WorkspaceDatasourceFactory {
workspaceMetadataVersion: number | null,
failOnMetadataCacheMiss = true,
): Promise<WorkspaceDataSource> {
const {
metadataVersion: cachedWorkspaceMetadataVersion,
objectMetadataMap: cachedObjectMetadataMap,
} = await this.getWorkspaceMetadataFromCache(
workspaceId,
failOnMetadataCacheMiss,
);
const cachedWorkspaceMetadataVersion =
await this.getWorkspaceMetadataVersionFromCache(
workspaceId,
failOnMetadataCacheMiss,
);
if (
workspaceMetadataVersion !== null &&
@ -89,6 +86,19 @@ export class WorkspaceDatasourceFactory {
let cachedEntitySchemas: EntitySchema[];
const cachedObjectMetadataMap =
await this.workspaceCacheStorageService.getObjectMetadataMap(
workspaceId,
cachedWorkspaceMetadataVersion,
);
if (!cachedObjectMetadataMap) {
throw new TwentyORMException(
`Workspace Schema not found for workspace ${workspaceId}`,
TwentyORMExceptionCode.METADATA_COLLECTION_NOT_FOUND,
);
}
if (cachedEntitySchemaOptions) {
cachedEntitySchemas = cachedEntitySchemaOptions.map(
(option) => new EntitySchema(option),
@ -181,13 +191,10 @@ export class WorkspaceDatasourceFactory {
);
}
private async getWorkspaceMetadataFromCache(
private async getWorkspaceMetadataVersionFromCache(
workspaceId: string,
failOnMetadataCacheMiss = true,
): Promise<{
metadataVersion: number;
objectMetadataMap: ObjectMetadataMap;
}> {
): Promise<number> {
let latestWorkspaceMetadataVersion =
await this.workspaceCacheStorageService.getMetadataVersion(workspaceId);
@ -217,22 +224,6 @@ export class WorkspaceDatasourceFactory {
);
}
const objectMetadataMap =
await this.workspaceCacheStorageService.getObjectMetadataMap(
workspaceId,
latestWorkspaceMetadataVersion,
);
if (!objectMetadataMap) {
throw new TwentyORMException(
`Object metadata map not found for workspace ${workspaceId}`,
TwentyORMExceptionCode.METADATA_COLLECTION_NOT_FOUND,
);
}
return {
metadataVersion: latestWorkspaceMetadataVersion,
objectMetadataMap,
};
return latestWorkspaceMetadataVersion;
}
}