Skip to content

Commit

Permalink
perf(core): Improve order quantity update performanc
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-advantitge authored Feb 11, 2021
1 parent 0c997bf commit 3c20837
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions packages/core/src/service/helpers/order-modifier/order-modifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,18 @@ export class OrderModifier {
if (!orderLine.items) {
orderLine.items = [];
}
const newOrderItems = [];
for (let i = currentQuantity; i < quantity; i++) {
const orderItem = await this.connection.getRepository(ctx, OrderItem).save(
new OrderItem({
listPrice: orderLine.productVariant.price,
listPriceIncludesTax: orderLine.productVariant.priceIncludesTax,
adjustments: [],
taxLines: [],
line: orderLine,
}),
);
orderLine.items.push(orderItem);
newOrderItems.push(new OrderItem({
listPrice: orderLine.productVariant.price,
listPriceIncludesTax: orderLine.productVariant.priceIncludesTax,
adjustments: [],
taxLines: [],
line: orderLine,
}));
}
await this.connection.getRepository(ctx, OrderItem).createQueryBuilder().insert().values(newOrderItems);
orderLine.items = orderLine.items.concat(newOrderItems);
} else if (quantity < currentQuantity) {
if (order.active) {
// When an Order is still active, it is fine to just delete
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/service/services/order.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1329,8 +1329,8 @@ export class OrderService {
updatedOrderLine ? [updatedOrderLine] : [],
);
await this.connection.getRepository(ctx, Order).save(order, { reload: false });
await this.connection.getRepository(ctx, OrderItem).save(updatedItems, { reload: false });
await this.connection.getRepository(ctx, ShippingLine).save(order.shippingLines, { reload: false });
await this.connection.getRepository(ctx, OrderItem).createQueryBuilder().insert().values(updatedItems);
await this.connection.getRepository(ctx, ShippingLine).createQueryBuilder().insert().values(order.shippingLines);
return order;
}

Expand Down

0 comments on commit 3c20837

Please sign in to comment.