* refactor: apply biome formatting to small packages + packages/lib Format packages/sms, packages/prisma, packages/platform/libraries, packages/platform/examples, packages/platform/types, packages/emails, and packages/lib. Excludes packages/platform/examples/base/src/pages/[bookingUid].tsx due to pre-existing lint errors. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * revert: remove packages/platform formatting changes Revert biome formatting for packages/platform as requested. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
40 lines
1022 B
TypeScript
40 lines
1022 B
TypeScript
import { unstable_cache } from "next/cache";
|
|
import { z } from "zod";
|
|
|
|
import prisma from "@calcom/prisma";
|
|
|
|
const computeInstallCountsFromDB = async (): Promise<Record<string, number>> => {
|
|
const mostPopularApps = z.array(z.object({ appId: z.string(), installCount: z.number() })).parse(
|
|
await prisma.$queryRaw`
|
|
SELECT
|
|
c."appId",
|
|
COUNT(*)::integer AS "installCount"
|
|
FROM
|
|
"Credential" c
|
|
WHERE
|
|
c."appId" IS NOT NULL
|
|
GROUP BY
|
|
c."appId"
|
|
ORDER BY
|
|
"installCount" DESC
|
|
`
|
|
);
|
|
return mostPopularApps.reduce(
|
|
(acc, { appId, installCount }) => {
|
|
acc[appId] = installCount;
|
|
return acc;
|
|
},
|
|
{} 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 };
|