From 7c6af13c6a0de969806ff06dffcf19072feb1222 Mon Sep 17 00:00:00 2001 From: nicktrn <55853254+nicktrn@users.noreply.github.com> Date: Fri, 10 Jan 2025 16:23:17 +0000 Subject: [PATCH] make query more legible --- .../app/v3/services/resumeAttempt.server.ts | 32 ++++++++----------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/apps/webapp/app/v3/services/resumeAttempt.server.ts b/apps/webapp/app/v3/services/resumeAttempt.server.ts index 0abf0bd48..fd3b70095 100644 --- a/apps/webapp/app/v3/services/resumeAttempt.server.ts +++ b/apps/webapp/app/v3/services/resumeAttempt.server.ts @@ -9,7 +9,7 @@ import { marqs } from "~/v3/marqs/index.server"; import { socketIo } from "../handleSocketIo.server"; import { sharedQueueTasks } from "../marqs/sharedQueueConsumer.server"; import { BaseService } from "./baseService.server"; -import { TaskRunAttempt } from "@trigger.dev/database"; +import { Prisma, TaskRunAttempt } from "@trigger.dev/database"; import { FINAL_ATTEMPT_STATUSES, FINAL_RUN_STATUSES, isFinalRunStatus } from "../taskStatus"; export class ResumeAttemptService extends BaseService { @@ -20,6 +20,16 @@ export class ResumeAttemptService extends BaseService { ): Promise { this._logger.debug(`ResumeAttemptService.call()`, params); + const latestAttemptSelect = { + orderBy: { + number: "desc", + }, + take: 1, + select: { + id: true, + }, + } satisfies Prisma.TaskRunInclude["attempts"]; + const attempt = await this._prisma.taskRunAttempt.findFirst({ where: { friendlyId: params.attemptFriendlyId, @@ -30,15 +40,7 @@ export class ResumeAttemptService extends BaseService { include: { taskRun: { include: { - attempts: { - orderBy: { - number: "desc", - }, - take: 1, - select: { - id: true, - }, - }, + attempts: latestAttemptSelect, }, }, }, @@ -53,15 +55,7 @@ export class ResumeAttemptService extends BaseService { include: { taskRun: { include: { - attempts: { - orderBy: { - number: "desc", - }, - take: 1, - select: { - id: true, - }, - }, + attempts: latestAttemptSelect, }, }, },