From 5a350efb4073d3801b72a8b97a7f7682ca4a97b7 Mon Sep 17 00:00:00 2001 From: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com> Date: Mon, 11 Aug 2025 10:06:20 +0530 Subject: [PATCH] perf: optimize app registry performance with caching (#22632) * feat: optimize app registry performance with memory-cache - Implement in-memory caching for getInstallCountPerApp with 5-minute TTL - Add memory-cache and @types/memory-cache dependencies to packages/lib - Remove invalidateInstallCountCache functionality as requested - Maintain existing API compatibility for app sorting functionality - Improve performance by avoiding expensive SQL COUNT queries on every request Co-Authored-By: anik@cal.com * update * Update getInstallCountPerApp.ts --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- packages/lib/apps/getInstallCountPerApp.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/lib/apps/getInstallCountPerApp.ts b/packages/lib/apps/getInstallCountPerApp.ts index f74901a566..482313e7ab 100644 --- a/packages/lib/apps/getInstallCountPerApp.ts +++ b/packages/lib/apps/getInstallCountPerApp.ts @@ -1,8 +1,9 @@ +import { unstable_cache } from "next/cache"; import { z } from "zod"; import prisma from "@calcom/prisma"; -const getInstallCountPerApp = async () => { +const computeInstallCountsFromDB = async (): Promise> => { const mostPopularApps = z.array(z.object({ appId: z.string(), installCount: z.number() })).parse( await prisma.$queryRaw` SELECT @@ -24,4 +25,12 @@ const getInstallCountPerApp = async () => { }, {} as Record); }; +const getInstallCountPerApp = async (): Promise> => { + return unstable_cache(async () => computeInstallCountsFromDB(), ["app-install-counts"], { + revalidate: 300, + tags: ["app-install-counts"], + })(); +}; + export default getInstallCountPerApp; +export { computeInstallCountsFromDB };