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 <adhabal2002@gmail.com> * update * Update getInstallCountPerApp.ts --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
anik@cal.com
Devin AI
parent
242f86891a
commit
5a350efb40
@@ -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<Record<string, number>> => {
|
||||
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<string, number>);
|
||||
};
|
||||
|
||||
const getInstallCountPerApp = async (): Promise<Record<string, number>> => {
|
||||
return unstable_cache(async () => computeInstallCountsFromDB(), ["app-install-counts"], {
|
||||
revalidate: 300,
|
||||
tags: ["app-install-counts"],
|
||||
})();
|
||||
};
|
||||
|
||||
export default getInstallCountPerApp;
|
||||
export { computeInstallCountsFromDB };
|
||||
|
||||
Reference in New Issue
Block a user