From b3904caacbe6079f548bac0d90961862fdc96331 Mon Sep 17 00:00:00 2001 From: Stephanos A Date: Wed, 17 Jun 2026 20:23:32 +0300 Subject: [PATCH] Refactor expireHolds to optimize expired seat hold deletion --- .../src/modules/seats/seats.service.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/apps/edr-passenger-api/src/modules/seats/seats.service.ts b/apps/edr-passenger-api/src/modules/seats/seats.service.ts index 88f9666bd..21060b595 100644 --- a/apps/edr-passenger-api/src/modules/seats/seats.service.ts +++ b/apps/edr-passenger-api/src/modules/seats/seats.service.ts @@ -547,16 +547,14 @@ export class SeatsService { @Cron(CronExpression.EVERY_MINUTE) async expireHolds() { - const expired = await this.prisma.seatHold.findMany({ where: { expiresAt: { lt: new Date() } } }); - for (const hold of expired) { + const now = new Date(); + const expired = await this.prisma.seatHold.findMany({ where: { expiresAt: { lt: now } } }); + if (expired.length === 0) return; + + const expiredIds = expired.map(h => h.id); + for (const hold of expired) { await this.releaseSeats(hold.seatIds); - try { - await this.prisma.seatHold.delete({ where: { id: hold.id } }); - } catch (err) { - if (err instanceof Error && !err.message.includes('P2025')) { - throw err; - } - } } + await this.prisma.seatHold.deleteMany({ where: { id: { in: expiredIds } } }); } }