Improve perf during repository creation in nested relations (#7132)
This commit is contained in:
@ -1,7 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
FindOptionsOrderValue,
|
FindOptionsOrderValue,
|
||||||
FindOptionsWhere,
|
FindOptionsWhere,
|
||||||
IsNull,
|
|
||||||
ObjectLiteral,
|
ObjectLiteral,
|
||||||
} from 'typeorm';
|
} from 'typeorm';
|
||||||
|
|
||||||
@ -40,33 +39,7 @@ export class GraphqlQueryParser {
|
|||||||
|
|
||||||
const parsedFilter = graphqlQueryFilterParser.parse(recordFilter);
|
const parsedFilter = graphqlQueryFilterParser.parse(recordFilter);
|
||||||
|
|
||||||
// if (!('deletedAt' in this.fieldMetadataMap)) {
|
|
||||||
return parsedFilter;
|
return parsedFilter;
|
||||||
// }
|
|
||||||
|
|
||||||
// return this.addDefaultSoftDeleteCondition(parsedFilter);
|
|
||||||
}
|
|
||||||
|
|
||||||
private addDefaultSoftDeleteCondition(
|
|
||||||
filter: FindOptionsWhere<ObjectLiteral> | FindOptionsWhere<ObjectLiteral>[],
|
|
||||||
): FindOptionsWhere<ObjectLiteral> | FindOptionsWhere<ObjectLiteral>[] {
|
|
||||||
if (Array.isArray(filter)) {
|
|
||||||
return filter.map((condition) =>
|
|
||||||
this.addSoftDeleteToCondition(condition),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.addSoftDeleteToCondition(filter);
|
|
||||||
}
|
|
||||||
|
|
||||||
private addSoftDeleteToCondition(
|
|
||||||
condition: FindOptionsWhere<ObjectLiteral>,
|
|
||||||
): FindOptionsWhere<ObjectLiteral> {
|
|
||||||
if (!('deletedAt' in condition)) {
|
|
||||||
return { ...condition, deletedAt: IsNull() };
|
|
||||||
}
|
|
||||||
|
|
||||||
return condition;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
parseOrder(
|
parseOrder(
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
|
DataSource,
|
||||||
FindManyOptions,
|
FindManyOptions,
|
||||||
FindOptionsRelations,
|
FindOptionsRelations,
|
||||||
In,
|
In,
|
||||||
@ -33,6 +34,7 @@ export class ProcessNestedRelationsHelper {
|
|||||||
nestedRelations: any,
|
nestedRelations: any,
|
||||||
limit: number,
|
limit: number,
|
||||||
authContext: any,
|
authContext: any,
|
||||||
|
dataSource: DataSource,
|
||||||
) {
|
) {
|
||||||
const relationFieldMetadata = parentObjectMetadataItem.fields[relationName];
|
const relationFieldMetadata = parentObjectMetadataItem.fields[relationName];
|
||||||
const relationMetadata = getRelationMetadata(relationFieldMetadata);
|
const relationMetadata = getRelationMetadata(relationFieldMetadata);
|
||||||
@ -49,11 +51,9 @@ export class ProcessNestedRelationsHelper {
|
|||||||
|
|
||||||
const referenceObjectMetadataName = referenceObjectMetadata.nameSingular;
|
const referenceObjectMetadataName = referenceObjectMetadata.nameSingular;
|
||||||
|
|
||||||
const relationRepository =
|
const relationRepository = await dataSource.getRepository(
|
||||||
await this.twentyORMGlobalManager.getRepositoryForWorkspace(
|
referenceObjectMetadataName,
|
||||||
authContext.workspace.id,
|
);
|
||||||
referenceObjectMetadataName,
|
|
||||||
);
|
|
||||||
|
|
||||||
const relationIds = parentObjectRecords.map((item) => item.id);
|
const relationIds = parentObjectRecords.map((item) => item.id);
|
||||||
|
|
||||||
@ -82,6 +82,7 @@ export class ProcessNestedRelationsHelper {
|
|||||||
nestedRelations as Record<string, FindOptionsRelations<ObjectLiteral>>,
|
nestedRelations as Record<string, FindOptionsRelations<ObjectLiteral>>,
|
||||||
limit,
|
limit,
|
||||||
authContext,
|
authContext,
|
||||||
|
dataSource,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -94,6 +95,7 @@ export class ProcessNestedRelationsHelper {
|
|||||||
nestedRelations: any,
|
nestedRelations: any,
|
||||||
limit: number,
|
limit: number,
|
||||||
authContext: any,
|
authContext: any,
|
||||||
|
dataSource: DataSource,
|
||||||
) {
|
) {
|
||||||
const relationFieldMetadata = parentObjectMetadataItem.fields[relationName];
|
const relationFieldMetadata = parentObjectMetadataItem.fields[relationName];
|
||||||
|
|
||||||
@ -104,11 +106,9 @@ export class ProcessNestedRelationsHelper {
|
|||||||
|
|
||||||
const referenceObjectMetadataName = referenceObjectMetadata.nameSingular;
|
const referenceObjectMetadataName = referenceObjectMetadata.nameSingular;
|
||||||
|
|
||||||
const relationRepository =
|
const relationRepository = dataSource.getRepository(
|
||||||
await this.twentyORMGlobalManager.getRepositoryForWorkspace(
|
referenceObjectMetadataName,
|
||||||
authContext.workspace.id,
|
);
|
||||||
referenceObjectMetadataName,
|
|
||||||
);
|
|
||||||
|
|
||||||
const relationIds = parentObjectRecords.map(
|
const relationIds = parentObjectRecords.map(
|
||||||
(item) => item[`${relationName}Id`],
|
(item) => item[`${relationName}Id`],
|
||||||
@ -139,6 +139,7 @@ export class ProcessNestedRelationsHelper {
|
|||||||
nestedRelations as Record<string, FindOptionsRelations<ObjectLiteral>>,
|
nestedRelations as Record<string, FindOptionsRelations<ObjectLiteral>>,
|
||||||
limit,
|
limit,
|
||||||
authContext,
|
authContext,
|
||||||
|
dataSource,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -150,6 +151,7 @@ export class ProcessNestedRelationsHelper {
|
|||||||
relations: Record<string, FindOptionsRelations<ObjectLiteral>>,
|
relations: Record<string, FindOptionsRelations<ObjectLiteral>>,
|
||||||
limit: number,
|
limit: number,
|
||||||
authContext: any,
|
authContext: any,
|
||||||
|
dataSource: DataSource,
|
||||||
) {
|
) {
|
||||||
for (const [relationName, nestedRelations] of Object.entries(relations)) {
|
for (const [relationName, nestedRelations] of Object.entries(relations)) {
|
||||||
const relationFieldMetadata =
|
const relationFieldMetadata =
|
||||||
@ -170,6 +172,7 @@ export class ProcessNestedRelationsHelper {
|
|||||||
nestedRelations,
|
nestedRelations,
|
||||||
limit,
|
limit,
|
||||||
authContext,
|
authContext,
|
||||||
|
dataSource,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
await this.processFromRelation(
|
await this.processFromRelation(
|
||||||
@ -180,6 +183,7 @@ export class ProcessNestedRelationsHelper {
|
|||||||
nestedRelations,
|
nestedRelations,
|
||||||
limit,
|
limit,
|
||||||
authContext,
|
authContext,
|
||||||
|
dataSource,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -48,11 +48,14 @@ export class GraphqlQueryFindManyResolverService {
|
|||||||
|
|
||||||
this.validateArgsOrThrow(args);
|
this.validateArgsOrThrow(args);
|
||||||
|
|
||||||
const repository =
|
const dataSource =
|
||||||
await this.twentyORMGlobalManager.getRepositoryForWorkspace(
|
await this.twentyORMGlobalManager.getDataSourceForWorkspace(
|
||||||
authContext.workspace.id,
|
authContext.workspace.id,
|
||||||
objectMetadataItem.nameSingular,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const repository = dataSource.getRepository(
|
||||||
|
objectMetadataItem.nameSingular,
|
||||||
|
);
|
||||||
const objectMetadataMap = generateObjectMetadataMap(
|
const objectMetadataMap = generateObjectMetadataMap(
|
||||||
objectMetadataCollection,
|
objectMetadataCollection,
|
||||||
);
|
);
|
||||||
@ -125,6 +128,7 @@ export class GraphqlQueryFindManyResolverService {
|
|||||||
relations,
|
relations,
|
||||||
limit,
|
limit,
|
||||||
authContext,
|
authContext,
|
||||||
|
dataSource,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user