From ae7c3e2d6ac80e5883e5354283ab0d3dbb5cc434 Mon Sep 17 00:00:00 2001 From: zomars Date: Mon, 5 Dec 2022 14:16:58 -0700 Subject: [PATCH] Removes unused cache --- lib/helpers/customPrisma.ts | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/lib/helpers/customPrisma.ts b/lib/helpers/customPrisma.ts index 075875aaf0..a09eda7a40 100644 --- a/lib/helpers/customPrisma.ts +++ b/lib/helpers/customPrisma.ts @@ -1,13 +1,11 @@ -import { hash } from "bcryptjs"; -import cache from "memory-cache"; import { NextMiddleware } from "next-api-middleware"; import { CONSOLE_URL } from "@calcom/lib/constants"; -import { prisma, customPrisma } from "@calcom/prisma"; +import { customPrisma, prisma } from "@calcom/prisma"; -import { PRISMA_CLIENT_CACHING_TIME } from "../../lib/constants"; +const LOCAL_CONSOLE_URL = process.env.NEXT_PUBLIC_CONSOLE_URL || CONSOLE_URL; -// This replaces the prisma client for the cusotm one if the key is valid +// This replaces the prisma client for the custom one if the key is valid export const customPrismaClient: NextMiddleware = async (req, res, next) => { const { query: { key }, @@ -20,9 +18,7 @@ export const customPrismaClient: NextMiddleware = async (req, res, next) => { } // If we have a key, we check if the deployment matching the key, has a databaseUrl value set. - const databaseUrl = await fetch( - `${process.env.NEXT_PUBLIC_CONSOLE_URL || CONSOLE_URL}/api/deployments/database?key=${key}` - ) + const databaseUrl = await fetch(`${LOCAL_CONSOLE_URL}/api/deployments/database?key=${key}`) .then((res) => res.json()) .then((res) => res.databaseUrl); @@ -30,18 +26,6 @@ export const customPrismaClient: NextMiddleware = async (req, res, next) => { res.status(400).json({ error: "no databaseUrl set up at your instance yet" }); return; } - // FIXME: Add some checks for the databaseUrl to make sure it is valid. (e.g. not a localhost) - const hashedUrl = await hash(databaseUrl, 12); - - const cachedPrisma = cache.get(hashedUrl); - /* We cache each cusotm prisma client for 24h to avoid too many requests to the database. */ - if (!cachedPrisma) { - cache.put( - hashedUrl, - customPrisma({ datasources: { db: { url: databaseUrl } } }), - PRISMA_CLIENT_CACHING_TIME // Cache the prisma client for 24 hours - ); - } req.prisma = customPrisma({ datasources: { db: { url: databaseUrl } } }); /* @note: In order to skip verifyApiKey for customPrisma requests,