From 487605df3ec42edc25207d343968d83c9d69ec3c Mon Sep 17 00:00:00 2001 From: Ahmad <103906421+ahmadk953@users.noreply.github.com> Date: Sun, 17 Mar 2024 00:48:01 -0400 Subject: [PATCH] Added Prisma Acelerate for Caching --- README.md | 2 +- .../(dashboard)/board/[boardId]/layout.tsx | 1 + .../[organizationId]/_components/board-list.tsx | 1 + lib/db.ts | 6 ++++-- lib/subscription.ts | 1 + package-lock.json | 12 ++++++++++++ package.json | 1 + 7 files changed, 21 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1cf9559..64afd78 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,6 @@ Currently, there is no documentation or wiki available but, I do plan to add one [Privacy Policy](https://tasko-omega.vercel.app/privacy-policy) -[Terms of Service](https://tasko-omega.vercel.app/terms-of-service) *There is no terms of service yet but, one will be added soon* +[Terms of Service](https://tasko-omega.vercel.app/terms-of-service) _There is no terms of service yet but, one will be added soon_ [License](https://github.com/ahmadk953/tasko/blob/main/LICENCE) diff --git a/app/(platform)/(dashboard)/board/[boardId]/layout.tsx b/app/(platform)/(dashboard)/board/[boardId]/layout.tsx index 66e6d90..2650ff7 100644 --- a/app/(platform)/(dashboard)/board/[boardId]/layout.tsx +++ b/app/(platform)/(dashboard)/board/[boardId]/layout.tsx @@ -41,6 +41,7 @@ const BoardIdLayout = async ({ id: params.boardId, orgId, }, + cacheStrategy: { ttl: 30, swr: 60 }, }); if (!board) notFound(); diff --git a/app/(platform)/(dashboard)/organization/[organizationId]/_components/board-list.tsx b/app/(platform)/(dashboard)/organization/[organizationId]/_components/board-list.tsx index 8bf90f6..eaee13f 100644 --- a/app/(platform)/(dashboard)/organization/[organizationId]/_components/board-list.tsx +++ b/app/(platform)/(dashboard)/organization/[organizationId]/_components/board-list.tsx @@ -25,6 +25,7 @@ export const BoardList = async () => { orderBy: { createdAt: 'desc', }, + cacheStrategy: { ttl: 30, swr: 60 }, }); const availableCount = await getAvailableCount(); diff --git a/lib/db.ts b/lib/db.ts index 56b4c34..cc0f542 100644 --- a/lib/db.ts +++ b/lib/db.ts @@ -1,9 +1,11 @@ import { PrismaClient } from '@prisma/client'; +import { withAccelerate } from '@prisma/extension-accelerate'; declare global { var prisma: PrismaClient | undefined; } -export const db = globalThis.prisma ?? new PrismaClient(); +export const db = new PrismaClient().$extends(withAccelerate()); -if (process.env.NODE_ENV !== 'production') globalThis.prisma = db; +// if (process.env.NODE_ENV !== 'production') globalThis.prisma = db; +// globalThis.prisma ?? diff --git a/lib/subscription.ts b/lib/subscription.ts index 8fefa9e..8a464a7 100644 --- a/lib/subscription.ts +++ b/lib/subscription.ts @@ -21,6 +21,7 @@ export const checkSubscription = async () => { stripeCustomerId: true, stripePriceId: true, }, + cacheStrategy: { ttl: 30, swr: 60 }, }); if (!orgSubscription) { diff --git a/package-lock.json b/package-lock.json index 68d3654..ef2e3af 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "@liveblocks/react": "^1.10.4", "@microsoft/eslint-formatter-sarif": "^3.0.0", "@prisma/client": "^5.11.0", + "@prisma/extension-accelerate": "^1.0.0", "@radix-ui/react-accordion": "^1.1.2", "@radix-ui/react-avatar": "^1.0.4", "@radix-ui/react-dialog": "^1.0.5", @@ -798,6 +799,17 @@ "integrity": "sha512-WXCuyoymvrS4zLz4wQagSsc3/nE6CHy8znyiMv8RKazKymOMd5o9FP5RGwGHAtgoxd+aB/BWqxuP/Ckfu7/3MA==", "devOptional": true }, + "node_modules/@prisma/extension-accelerate": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@prisma/extension-accelerate/-/extension-accelerate-1.0.0.tgz", + "integrity": "sha512-5oSpPtKCMfTl/sSXaS/7vBsPqfm+eEVB6/5KPBJITFatDoFcmjx/PIC/T93mHLiHI98xKwosPN59NGXjDDhcFA==", + "engines": { + "node": ">=16" + }, + "peerDependencies": { + "@prisma/client": ">=4.16.1" + } + }, "node_modules/@prisma/fetch-engine": { "version": "5.11.0", "resolved": "https://registry.npmjs.org/@prisma/fetch-engine/-/fetch-engine-5.11.0.tgz", diff --git a/package.json b/package.json index 21ec2e5..425b2bb 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "@liveblocks/react": "^1.10.4", "@microsoft/eslint-formatter-sarif": "^3.0.0", "@prisma/client": "^5.11.0", + "@prisma/extension-accelerate": "^1.0.0", "@radix-ui/react-accordion": "^1.1.2", "@radix-ui/react-avatar": "^1.0.4", "@radix-ui/react-dialog": "^1.0.5",