From f4b0772746aaf6f0188ad33e08a8e5c66ddf43b1 Mon Sep 17 00:00:00 2001 From: Jaideep Guntupalli <63718527+JaideepGuntupalli@users.noreply.github.com> Date: Mon, 17 Jul 2023 15:21:35 +0530 Subject: [PATCH] refactor: renamed getMostPopularApps function to getInstallCountPerApp (#10140) Co-authored-by: Peer Richelsen --- packages/app-store/_appRegistry.ts | 10 +++++----- ...{getMostPopularApps.ts => getInstallCountPerApp.ts} | 4 ++-- .../routers/loggedInViewer/integrations.handler.ts | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) rename packages/lib/apps/{getMostPopularApps.ts => getInstallCountPerApp.ts} (87%) diff --git a/packages/app-store/_appRegistry.ts b/packages/app-store/_appRegistry.ts index 3cc83ef7b7..d7913a279a 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 fa1fb7ac71..f74901a566 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); }; -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 57488cce25..09e711b657 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; }); }