Skip to content

Commit 5a350ef

Browse files
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: [email protected] <[email protected]> * update * Update getInstallCountPerApp.ts --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 242f868 commit 5a350ef

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

packages/lib/apps/getInstallCountPerApp.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import { unstable_cache } from "next/cache";
12
import { z } from "zod";
23

34
import prisma from "@calcom/prisma";
45

5-
const getInstallCountPerApp = async () => {
6+
const computeInstallCountsFromDB = async (): Promise<Record<string, number>> => {
67
const mostPopularApps = z.array(z.object({ appId: z.string(), installCount: z.number() })).parse(
78
await prisma.$queryRaw`
89
SELECT
@@ -24,4 +25,12 @@ const getInstallCountPerApp = async () => {
2425
}, {} as Record<string, number>);
2526
};
2627

28+
const getInstallCountPerApp = async (): Promise<Record<string, number>> => {
29+
return unstable_cache(async () => computeInstallCountsFromDB(), ["app-install-counts"], {
30+
revalidate: 300,
31+
tags: ["app-install-counts"],
32+
})();
33+
};
34+
2735
export default getInstallCountPerApp;
36+
export { computeInstallCountsFromDB };

0 commit comments

Comments
 (0)