perf: Enable Prisma Optimize (#44)
* Enable Prisma Optimize * Added Environment variable to toggle on and off the Prisma Optimize --------- Co-authored-by: harshsbhat <icybhat@gmail.com>
This commit is contained in:
committed by
GitHub
parent
75afd339ea
commit
0c072579b9
@@ -127,6 +127,12 @@ pnpm install
|
||||
|
||||
Once the app is added you can add the Client ID under ``GITHUB_ID``and CLIENT SECRET under ```GITHUB_SECRET```
|
||||
</Step>
|
||||
<Step title="Optional: Enable prisma optimize">
|
||||
To enable Prisma Optimize and get insights on queires you can add this in you .env
|
||||
```bash
|
||||
ENABLE_PRISMA_CLIENT=true
|
||||
```
|
||||
</Step>
|
||||
</Steps>
|
||||
|
||||
## Running Unsend locally
|
||||
|
@@ -60,6 +60,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@next/eslint-plugin-next": "^14.2.2",
|
||||
"@prisma/extension-optimize": "^0.10.0",
|
||||
"@types/eslint": "^8.56.2",
|
||||
"@types/mime-types": "^2.1.4",
|
||||
"@types/node": "^20.11.20",
|
||||
|
@@ -3,6 +3,7 @@
|
||||
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
previewFeatures = ["tracing"]
|
||||
}
|
||||
|
||||
datasource db {
|
||||
|
@@ -46,6 +46,10 @@ export const env = createEnv({
|
||||
ADMIN_EMAIL: z.string().optional(),
|
||||
DISCORD_WEBHOOK_URL: z.string().optional(),
|
||||
REDIS_URL: z.string(),
|
||||
ENABLE_PRISMA_CLIENT: z
|
||||
.string()
|
||||
.default("false")
|
||||
.transform((str) => str === "true"), // Converts string "true" to boolean true
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -84,6 +88,7 @@ export const env = createEnv({
|
||||
ADMIN_EMAIL: process.env.ADMIN_EMAIL,
|
||||
DISCORD_WEBHOOK_URL: process.env.DISCORD_WEBHOOK_URL,
|
||||
REDIS_URL: process.env.REDIS_URL,
|
||||
ENABLE_PRISMA_CLIENT: process.env.ENABLE_PRISMA_CLIENT, // Add this line
|
||||
},
|
||||
/**
|
||||
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially
|
||||
|
@@ -1,12 +1,18 @@
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
|
||||
import { withOptimize } from "@prisma/extension-optimize";
|
||||
import { env } from "~/env";
|
||||
|
||||
const createPrismaClient = () =>
|
||||
new PrismaClient({
|
||||
const createPrismaClient = () => {
|
||||
const client = new PrismaClient({
|
||||
log:
|
||||
env.NODE_ENV === "development" ? ["query", "error", "warn"] : ["error"],
|
||||
});
|
||||
if (env.ENABLE_PRISMA_CLIENT) {
|
||||
return client.$extends(withOptimize());
|
||||
}
|
||||
|
||||
return client;
|
||||
};
|
||||
|
||||
// eslint-disable-next-line no-undef
|
||||
const globalForPrisma = globalThis as unknown as {
|
||||
|
Reference in New Issue
Block a user