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