refactor: renamed getMostPopularApps function to getInstallCountPerApp (#10140)
Co-authored-by: Peer Richelsen <peeroke@gmail.com>
This commit is contained in:
1 parent
1a605b555a
commit
f4b0772746
3 files changed
+11
-11
No files matched your search
@@ -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 }),
|
||||
});
|
||||
|
||||
+2
-2
@@ -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;
|
||||
@@ -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;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user