From fa563f29ab144879d60961c9808df97f7ba126de Mon Sep 17 00:00:00 2001 From: Michael Bromley Date: Tue, 28 Sep 2021 09:28:49 +0200 Subject: [PATCH] perf(core): Simplify hot DB query for active order --- .../helpers/active-order/active-order.service.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/core/src/service/helpers/active-order/active-order.service.ts b/packages/core/src/service/helpers/active-order/active-order.service.ts index c5b85a7ed2..6062cf0567 100644 --- a/packages/core/src/service/helpers/active-order/active-order.service.ts +++ b/packages/core/src/service/helpers/active-order/active-order.service.ts @@ -5,10 +5,15 @@ import { InternalServerError } from '../../../common/error/errors'; import { Order } from '../../../entity/order/order.entity'; import { OrderService } from '../../services/order.service'; import { SessionService } from '../../services/session.service'; +import { TransactionalConnection } from '../../transaction/transactional-connection'; @Injectable() export class ActiveOrderService { - constructor(private sessionService: SessionService, private orderService: OrderService) {} + constructor( + private sessionService: SessionService, + private orderService: OrderService, + private connection: TransactionalConnection, + ) {} /** * @description @@ -25,7 +30,13 @@ export class ActiveOrderService { throw new InternalServerError(`error.no-active-session`); } let order = ctx.session.activeOrderId - ? await this.orderService.findOne(ctx, ctx.session.activeOrderId) + ? await this.connection + .getRepository(ctx, Order) + .createQueryBuilder('order') + .leftJoin('order.channels', 'channel') + .where('order.id = :orderId', { orderId: ctx.session.activeOrderId }) + .andWhere('channel.id = :channelId', { channelId: ctx.channelId }) + .getOne() : undefined; if (order && order.active === false) { // edge case where an inactive order may not have been