Przeglądaj źródła

perf(core): Upgrade sql requests for more performant memory usage with big datasets (#2741)

Eugene Nitsenko 1 rok temu
rodzic
commit
65888cba31

+ 4 - 0
packages/core/src/service/services/product-option-group.service.ts

@@ -133,6 +133,8 @@ export class ProductOptionGroupService {
      */
     async deleteGroupAndOptionsFromProduct(ctx: RequestContext, id: ID, productId: ID) {
         const optionGroup = await this.connection.getEntityOrThrow(ctx, ProductOptionGroup, id, {
+            relationLoadStrategy: 'query',
+            loadEagerRelations: false,
             relations: ['options', 'product'],
         });
         const deletedOptionGroup = new ProductOptionGroup(optionGroup);
@@ -165,6 +167,8 @@ export class ProductOptionGroupService {
             // hard delete
 
             const product = await this.connection.getRepository(ctx, Product).findOne({
+                relationLoadStrategy: 'query',
+                loadEagerRelations: false,
                 where: { id: productId },
                 relations: ['optionGroups'],
             });

+ 4 - 0
packages/core/src/service/services/product.service.ts

@@ -271,6 +271,8 @@ export class ProductService {
 
     async softDelete(ctx: RequestContext, productId: ID): Promise<DeletionResponse> {
         const product = await this.connection.getEntityOrThrow(ctx, Product, productId, {
+            relationLoadStrategy: 'query',
+            loadEagerRelations: false,
             channelId: ctx.channelId,
             relations: ['variants', 'optionGroups'],
         });
@@ -449,6 +451,8 @@ export class ProductService {
 
     private async getProductWithOptionGroups(ctx: RequestContext, productId: ID): Promise<Product> {
         const product = await this.connection.getRepository(ctx, Product).findOne({
+            relationLoadStrategy: 'query',
+            loadEagerRelations: false,
             where: { id: productId, deletedAt: IsNull() },
             relations: ['optionGroups', 'variants', 'variants.options'],
         });