feat: Setups prisma accelerate (#11324)
This commit is contained in:
1 parent
21a0b67b5a
commit
560ec244e8
15 files changed
+150
-49
No files matched your search
@@ -74,6 +74,7 @@ test("Calendar Cache is being called", async () => {
|
||||
// First call won't have a cache
|
||||
.mockResolvedValueOnce(null)
|
||||
// Second call will have a cache
|
||||
// @ts-expect-error expects a "null" here due to previous call
|
||||
.mockResolvedValueOnce(calendarCacheResponse);
|
||||
|
||||
// prismaMock.calendarCache.create.mock.
|
||||
|
||||
@@ -50,6 +50,8 @@ export async function getServerSession(options: {
|
||||
where: {
|
||||
email: token.email.toLowerCase(),
|
||||
},
|
||||
// TODO: Re-enable once we get confirmation from compliance that this is okay.
|
||||
// cacheStrategy: { ttl: 60, swr: 1 },
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
import type {
|
||||
Account,
|
||||
IdentityProvider,
|
||||
Prisma,
|
||||
PrismaClient,
|
||||
User,
|
||||
VerificationToken,
|
||||
} from "@prisma/client";
|
||||
import type { Account, IdentityProvider, Prisma, User, VerificationToken } from "@prisma/client";
|
||||
import { PrismaClientKnownRequestError } from "@prisma/client/runtime/library";
|
||||
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
|
||||
import { identityProviderNameMap } from "./identityProviderNameMap";
|
||||
|
||||
/** @return { import("next-auth/adapters").Adapter } */
|
||||
|
||||
@@ -82,7 +82,8 @@ const getUserAdminTeams = async ({
|
||||
name: user.name || "me",
|
||||
logo: user?.avatar === "" ? null : user?.avatar,
|
||||
isUser: true,
|
||||
...(includeCredentials && { credentials: user.credentials }),
|
||||
credentials: includeCredentials ? [] : user.credentials,
|
||||
parent: null,
|
||||
};
|
||||
teams.unshift(userObject);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { Prisma } from "@prisma/client";
|
||||
import { PrismaClient as PrismaClientWithoutExtension } from "@prisma/client";
|
||||
import { withAccelerate } from "@prisma/extension-accelerate";
|
||||
|
||||
import { bookingReferenceMiddleware } from "./middleware";
|
||||
|
||||
@@ -14,8 +15,8 @@ if (!!process.env.NEXT_PUBLIC_DEBUG) prismaOptions.log = ["query", "error", "war
|
||||
|
||||
const prismaWithoutClientExtensions = new PrismaClientWithoutExtension(prismaOptions);
|
||||
|
||||
export const customPrisma = (options: Prisma.PrismaClientOptions) =>
|
||||
new PrismaClientWithoutExtension({ ...prismaOptions, ...options });
|
||||
export const customPrisma = (options?: Prisma.PrismaClientOptions) =>
|
||||
new PrismaClientWithoutExtension({ ...prismaOptions, ...options }).$extends(withAccelerate());
|
||||
|
||||
// If any changed on middleware server restart is required
|
||||
// TODO: Migrate it to $extends
|
||||
@@ -23,7 +24,10 @@ bookingReferenceMiddleware(prismaWithoutClientExtensions);
|
||||
|
||||
// FIXME: Due to some reason, there are types failing in certain places due to the $extends. Fix it and then enable it
|
||||
// Specifically we get errors like `Type 'string | Date | null | undefined' is not assignable to type 'Exact<string | Date | null | undefined, string | Date | null | undefined>'`
|
||||
// const prismaWithClientExtensions = prismaWithoutClientExtensions.$extends({
|
||||
const prismaWithClientExtensions = prismaWithoutClientExtensions
|
||||
//
|
||||
.$extends(withAccelerate());
|
||||
// .$extends({
|
||||
// query: {
|
||||
// $allModels: {
|
||||
// async $allOperations({ model, operation, args, query }) {
|
||||
@@ -51,7 +55,7 @@ bookingReferenceMiddleware(prismaWithoutClientExtensions);
|
||||
// },
|
||||
// })
|
||||
|
||||
const prismaWithClientExtensions = prismaWithoutClientExtensions;
|
||||
// const prismaWithClientExtensions = prismaWithoutClientExtensions;
|
||||
|
||||
export const prisma = (globalThis.prisma as typeof prismaWithClientExtensions) || prismaWithClientExtensions;
|
||||
|
||||
@@ -59,7 +63,7 @@ if (process.env.NODE_ENV !== "production") {
|
||||
globalThis.prisma = prisma;
|
||||
}
|
||||
|
||||
export type PrismaClient = typeof prisma;
|
||||
export type PrismaClient = typeof prismaWithClientExtensions;
|
||||
export default prisma;
|
||||
|
||||
export * from "./selects";
|
||||
@@ -24,9 +24,10 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@calcom/lib": "*",
|
||||
"@prisma/client": "^5.0.0",
|
||||
"@prisma/generator-helper": "^5.0.0",
|
||||
"prisma": "^5.0.0",
|
||||
"@prisma/client": "^5.2.0",
|
||||
"@prisma/extension-accelerate": "^0.6.2",
|
||||
"@prisma/generator-helper": "^5.2.0",
|
||||
"prisma": "^5.2.0",
|
||||
"ts-node": "^10.9.1",
|
||||
"zod": "^3.22.2",
|
||||
"zod-prisma": "^0.5.4"
|
||||
|
||||
Reference in new issue
Block a user