Skip to content

Scheduling infrastructure for absolutely everyone.

refactor: renamed getMostPopularApps function to getInstallCountPerApp (#10140)

Jaideep Guntupallif4b0772746aa
diff --git a/packages/app-store/_appRegistry.ts b/packages/app-store/_appRegistry.ts
index 3cc83ef7b7d..d7913a279a7 100644
--- a/packages/app-store/_appRegistry.ts
+++ b/packages/app-store/_appRegistry.ts
@@ -1,7 +1,7 @@
import { appStoreMetadata } from "@calcom/app-store/appStoreMetaData";
import { getAppFromSlug } from "@calcom/app-store/utils";
import type { UserAdminTeams } from "@calcom/features/ee/teams/lib/getUserAdminTeams";
-import getMostPopularApps from "@calcom/lib/apps/getMostPopularApps";
+import getInstallCountPerApp from "@calcom/lib/apps/getInstallCountPerApp";
import prisma, { safeAppSelect, safeCredentialSelect } from "@calcom/prisma";
import { userMetadata } from "@calcom/prisma/zod-utils";
import type { AppFrontendPayload as App } from "@calcom/types/App";
@@ -37,7 +37,7 @@ export async function getAppRegistry() {
select: { dirName: true, slug: true, categories: true, enabled: true },
});
const apps = [] as App[];
- const mostPopularApps = await getMostPopularApps();
+ const installCountPerApp = await getInstallCountPerApp();
for await (const dbapp of dbApps) {
const app = await getAppWithMetadata(dbapp);
if (!app) continue;
@@ -50,7 +50,7 @@ export async function getAppRegistry() {
category: app.category || "other",
installed:
true /* All apps from DB are considered installed by default. @TODO: Add and filter our by `enabled` property */,
- installCount: mostPopularApps[dbapp.slug] || 0,
+ installCount: installCountPerApp[dbapp.slug] || 0,
});
}
return apps;
@@ -94,7 +94,7 @@ export async function getAppRegistryWithCredentials(userId: number, userAdminTea
credentials: Credential[];
isDefault?: boolean;
})[];
- const mostPopularApps = await getMostPopularApps();
+ const installCountPerApp = await getInstallCountPerApp();
for await (const dbapp of dbApps) {
const app = await getAppWithMetadata(dbapp);
if (!app) continue;
@@ -121,7 +121,7 @@ export async function getAppRegistryWithCredentials(userId: number, userAdminTea
categories: dbapp.categories,
credentials: dbapp.credentials,
installed: true,
- installCount: mostPopularApps[dbapp.slug] || 0,
+ installCount: installCountPerApp[dbapp.slug] || 0,
isDefault: usersDefaultApp === dbapp.slug,
...(app.dependencies && { dependencyData }),
});
diff --git a/packages/lib/apps/getMostPopularApps.ts b/packages/lib/apps/getInstallCountPerApp.ts
similarity index 87%
rename from packages/lib/apps/getMostPopularApps.ts
rename to packages/lib/apps/getInstallCountPerApp.ts
index fa1fb7ac71c..f74901a566b 100644
--- a/packages/lib/apps/getMostPopularApps.ts
+++ b/packages/lib/apps/getInstallCountPerApp.ts
@@ -2,7 +2,7 @@ import { z } from "zod";
import prisma from "@calcom/prisma";
-const getMostPopularApps = async () => {
+const getInstallCountPerApp = async () => {
const mostPopularApps = z.array(z.object({ appId: z.string(), installCount: z.number() })).parse(
await prisma.$queryRaw`
SELECT
@@ -24,4 +24,4 @@ const getMostPopularApps = async () => {
}, {} as Record<string, number>);
};
-export default getMostPopularApps;
+export default getInstallCountPerApp;
diff --git a/packages/trpc/server/routers/loggedInViewer/integrations.handler.ts b/packages/trpc/server/routers/loggedInViewer/integrations.handler.ts
index 57488cce253..09e711b6572 100644
--- a/packages/trpc/server/routers/loggedInViewer/integrations.handler.ts
+++ b/packages/trpc/server/routers/loggedInViewer/integrations.handler.ts
@@ -1,5 +1,5 @@
import getEnabledApps from "@calcom/lib/apps/getEnabledApps";
-import getMostPopularApps from "@calcom/lib/apps/getMostPopularApps";
+import getInstallCountPerApp from "@calcom/lib/apps/getInstallCountPerApp";
import prisma from "@calcom/prisma";
import { MembershipRole } from "@calcom/prisma/enums";
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
@@ -177,12 +177,12 @@ export const integrationsHandler = async ({ ctx, input }: IntegrationsOptions) =
}
if (sortByMostPopular) {
- const mostPopularApps = await getMostPopularApps();
+ const installCountPerApp = await getInstallCountPerApp();
// sort the apps array by the most popular apps
apps.sort((a, b) => {
- const aCount = mostPopularApps[a.slug] || 0;
- const bCount = mostPopularApps[b.slug] || 0;
+ const aCount = installCountPerApp[a.slug] || 0;
+ const bCount = installCountPerApp[b.slug] || 0;
return bCount - aCount;
});
}