Improve perf during repository creation in nested relations (#7132)
This commit is contained in:
@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user