Skip to content

Commit cb24e5d

Browse files
authored
perf: remove 2 DB fetches by removing getFacetedValues (calcom#21808)
* perf: remove 2 server fetches by removing getFacetedValues * fix * fix * use set * fix
1 parent 8c5aebd commit cb24e5d

5 files changed

Lines changed: 26 additions & 75 deletions

File tree

apps/web/app/(use-page-wrapper)/settings/organizations/(org-user-only)/members/page.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { _generateMetadata } from "app/_utils";
33
import { unstable_cache } from "next/cache";
44

55
import { AttributeRepository } from "@calcom/lib/server/repository/attribute";
6+
import { MembershipRole } from "@calcom/prisma/enums";
67
import { viewerOrganizationsRouter } from "@calcom/trpc/server/routers/viewer/organizations/_router";
78

89
import { MembersView } from "~/members/members-view";
@@ -26,12 +27,20 @@ const getCachedAttributes = unstable_cache(
2627

2728
const Page = async () => {
2829
const orgCaller = await createRouterCaller(viewerOrganizationsRouter);
29-
const [org, teams, facetedTeamValues] = await Promise.all([
30-
orgCaller.listCurrent(),
31-
orgCaller.getTeams(),
32-
orgCaller.getFacetedValues(),
33-
]);
30+
const [org, teams] = await Promise.all([orgCaller.listCurrent(), orgCaller.getTeams()]);
3431
const attributes = await getCachedAttributes(org.id);
32+
const facetedTeamValues = {
33+
roles: [MembershipRole.OWNER, MembershipRole.ADMIN, MembershipRole.MEMBER],
34+
teams,
35+
attributes: attributes.map((attribute) => ({
36+
id: attribute.id,
37+
name: attribute.name,
38+
options: Array.from(new Set(attribute.options.map((option) => option.value))).map((value) => ({
39+
value,
40+
})),
41+
})),
42+
};
43+
3544
return (
3645
<MembersView org={org} teams={teams} facetedTeamValues={facetedTeamValues} attributes={attributes} />
3746
);

packages/features/users/components/UserTable/UserListTable.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
} from "@calcom/lib/csvUtils";
3131
import { getUserAvatarUrl } from "@calcom/lib/getAvatarUrl";
3232
import { useLocale } from "@calcom/lib/hooks/useLocale";
33+
import type { MembershipRole } from "@calcom/prisma/enums";
3334
import { trpc } from "@calcom/trpc";
3435
import type { RouterOutputs } from "@calcom/trpc/react";
3536
import classNames from "@calcom/ui/classNames";
@@ -109,8 +110,18 @@ function reducer(state: UserTableState, action: UserTableAction): UserTableState
109110
export type UserListTableProps = {
110111
org: RouterOutputs["viewer"]["organizations"]["listCurrent"];
111112
teams: RouterOutputs["viewer"]["organizations"]["getTeams"];
112-
facetedTeamValues?: RouterOutputs["viewer"]["organizations"]["getFacetedValues"];
113113
attributes?: RouterOutputs["viewer"]["attributes"]["list"];
114+
facetedTeamValues?: {
115+
roles: MembershipRole[];
116+
teams: RouterOutputs["viewer"]["organizations"]["getTeams"];
117+
attributes: {
118+
id: string;
119+
name: string;
120+
options: {
121+
value: string;
122+
}[];
123+
}[];
124+
};
114125
};
115126

116127
export function UserListTable(props: UserListTableProps) {

packages/trpc/server/routers/viewer/organizations/_router.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ import { ZSetPasswordSchema } from "./setPassword.schema";
2929
import { ZUpdateInputSchema } from "./update.schema";
3030
import { ZUpdateUserInputSchema } from "./updateUser.schema";
3131

32-
const NAMESPACE = "organizations";
33-
34-
const namespaced = (s: string) => `${NAMESPACE}.${s}`;
35-
3632
export const viewerOrganizationsRouter = router({
3733
getOrganizationOnboarding: authedProcedure.query(async (opts) => {
3834
const { default: handler } = await import("./getOrganizationOnboarding.handler");
@@ -162,8 +158,4 @@ export const viewerOrganizationsRouter = router({
162158
const { default: handler } = await import("./createPhoneCall.handler");
163159
return handler(opts);
164160
}),
165-
getFacetedValues: authedProcedure.query(async (opts) => {
166-
const { default: handler } = await import("./getFacetedValues.handler");
167-
return handler(opts);
168-
}),
169161
});

packages/trpc/server/routers/viewer/organizations/getFacetedValues.handler.ts

Lines changed: 0 additions & 54 deletions
This file was deleted.

packages/trpc/server/routers/viewer/organizations/getFacetedValues.schema.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)