From 5c879e7145a64e01b49dd1559d9d4636612c1be6 Mon Sep 17 00:00:00 2001 From: Michael Bromley Date: Tue, 16 Feb 2021 16:04:53 +0100 Subject: [PATCH] perf(core): Correctly optimized OrderItem persistence --- packages/core/e2e/order-taxes.e2e-spec.ts | 2 -- .../core/src/service/helpers/order-modifier/order-modifier.ts | 4 +++- packages/core/src/service/services/order.service.ts | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/core/e2e/order-taxes.e2e-spec.ts b/packages/core/e2e/order-taxes.e2e-spec.ts index 40529e9326..b7e2ea9432 100644 --- a/packages/core/e2e/order-taxes.e2e-spec.ts +++ b/packages/core/e2e/order-taxes.e2e-spec.ts @@ -1,7 +1,6 @@ /* tslint:disable:no-non-null-assertion */ import { summate } from '@vendure/common/lib/shared-utils'; import { createErrorResultGuard, createTestEnvironment, ErrorResultGuard } from '@vendure/testing'; -import gql from 'graphql-tag'; import path from 'path'; import { initialData } from '../../../e2e-common/e2e-initial-data'; @@ -11,7 +10,6 @@ import { testSuccessfulPaymentMethod } from './fixtures/test-payment-methods'; import { GetProductsWithVariantPrices, UpdateChannel } from './graphql/generated-e2e-admin-types'; import { AddItemToOrder, - AdjustmentType, GetActiveOrderWithPriceData, TestOrderFragmentFragment, UpdatedOrderFragment, diff --git a/packages/core/src/service/helpers/order-modifier/order-modifier.ts b/packages/core/src/service/helpers/order-modifier/order-modifier.ts index 211bbc53a5..243ccef293 100644 --- a/packages/core/src/service/helpers/order-modifier/order-modifier.ts +++ b/packages/core/src/service/helpers/order-modifier/order-modifier.ts @@ -170,7 +170,9 @@ export class OrderModifier { .values(newOrderItems) .execute(); newOrderItems.forEach((item, i) => (item.id = identifiers[i].id)); - orderLine.items.push(...newOrderItems); + orderLine.items = await this.connection + .getRepository(ctx, OrderItem) + .find({ where: { line: orderLine } }); } else if (quantity < currentQuantity) { if (order.active) { // When an Order is still active, it is fine to just delete diff --git a/packages/core/src/service/services/order.service.ts b/packages/core/src/service/services/order.service.ts index 9fb702c2be..25dc61843e 100644 --- a/packages/core/src/service/services/order.service.ts +++ b/packages/core/src/service/services/order.service.ts @@ -1339,6 +1339,7 @@ export class OrderService { .getRepository(ctx, OrderItem) .createQueryBuilder() .insert() + .into(OrderItem, [...updateFields, 'id', 'lineId']) .values(updatedItems) .orUpdate({ conflict_target: ['id'],