From 9941186a74a4140b5baa79a94d0ff2e6da2c3e2d Mon Sep 17 00:00:00 2001 From: Morgan Vernay Date: Thu, 12 Oct 2023 17:20:44 +0300 Subject: [PATCH] fix(paypal/add): prisma count is slow --- packages/app-store/paypal/api/add.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/app-store/paypal/api/add.ts b/packages/app-store/paypal/api/add.ts index 79a044786b..46f4110e43 100644 --- a/packages/app-store/paypal/api/add.ts +++ b/packages/app-store/paypal/api/add.ts @@ -13,13 +13,15 @@ async function getHandler(req: NextApiRequest, res: NextApiResponse) { return res.status(401).json({ message: "You must be logged in to do this" }); } try { - const alreadyInstalled = - (await prisma.credential.count({ + const alreadyInstalled = Boolean( + await prisma.credential.findFirst({ + select: { id: true }, where: { appId: config.slug, ...(Boolean(teamId) ? { AND: [{ userId: userId }, { teamId }] } : { userId: userId }), }, - })) > 0; + }) + ); if (alreadyInstalled) { throw new Error("App is already installed");