perf: remove 2 DB fetches by removing getFacetedValues (#21808)
* perf: remove 2 server fetches by removing getFacetedValues * fix * fix * use set * fix
This commit is contained in:
1 parent
8c5aebdca1
commit
cb24e5d0aa
5 files changed
+26
-75
No files matched your search
@@ -30,6 +30,7 @@ import {
|
||||
} from "@calcom/lib/csvUtils";
|
||||
import { getUserAvatarUrl } from "@calcom/lib/getAvatarUrl";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import type { MembershipRole } from "@calcom/prisma/enums";
|
||||
import { trpc } from "@calcom/trpc";
|
||||
import type { RouterOutputs } from "@calcom/trpc/react";
|
||||
import classNames from "@calcom/ui/classNames";
|
||||
@@ -109,8 +110,18 @@ function reducer(state: UserTableState, action: UserTableAction): UserTableState
|
||||
export type UserListTableProps = {
|
||||
org: RouterOutputs["viewer"]["organizations"]["listCurrent"];
|
||||
teams: RouterOutputs["viewer"]["organizations"]["getTeams"];
|
||||
facetedTeamValues?: RouterOutputs["viewer"]["organizations"]["getFacetedValues"];
|
||||
attributes?: RouterOutputs["viewer"]["attributes"]["list"];
|
||||
facetedTeamValues?: {
|
||||
roles: MembershipRole[];
|
||||
teams: RouterOutputs["viewer"]["organizations"]["getTeams"];
|
||||
attributes: {
|
||||
id: string;
|
||||
name: string;
|
||||
options: {
|
||||
value: string;
|
||||
}[];
|
||||
}[];
|
||||
};
|
||||
};
|
||||
|
||||
export function UserListTable(props: UserListTableProps) {
|
||||
|
||||
@@ -29,10 +29,6 @@ import { ZSetPasswordSchema } from "./setPassword.schema";
|
||||
import { ZUpdateInputSchema } from "./update.schema";
|
||||
import { ZUpdateUserInputSchema } from "./updateUser.schema";
|
||||
|
||||
const NAMESPACE = "organizations";
|
||||
|
||||
const namespaced = (s: string) => `${NAMESPACE}.${s}`;
|
||||
|
||||
export const viewerOrganizationsRouter = router({
|
||||
getOrganizationOnboarding: authedProcedure.query(async (opts) => {
|
||||
const { default: handler } = await import("./getOrganizationOnboarding.handler");
|
||||
@@ -162,8 +158,4 @@ export const viewerOrganizationsRouter = router({
|
||||
const { default: handler } = await import("./createPhoneCall.handler");
|
||||
return handler(opts);
|
||||
}),
|
||||
getFacetedValues: authedProcedure.query(async (opts) => {
|
||||
const { default: handler } = await import("./getFacetedValues.handler");
|
||||
return handler(opts);
|
||||
}),
|
||||
});
|
||||
@@ -1,54 +0,0 @@
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
|
||||
import { TRPCError } from "@trpc/server";
|
||||
|
||||
import type { TrpcSessionUser } from "../../../types";
|
||||
|
||||
type DeleteOptions = {
|
||||
ctx: {
|
||||
user: NonNullable<TrpcSessionUser>;
|
||||
};
|
||||
};
|
||||
|
||||
export const getFacetedValuesHandler = async ({ ctx }: DeleteOptions) => {
|
||||
const { user } = ctx;
|
||||
|
||||
const organizationId = user.organization?.id;
|
||||
|
||||
if (!organizationId) {
|
||||
throw new TRPCError({ code: "NOT_FOUND", message: "Organization not found" });
|
||||
}
|
||||
const [teams, attributes] = await Promise.all([
|
||||
prisma.team.findMany({
|
||||
where: {
|
||||
parentId: organizationId,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
},
|
||||
}),
|
||||
prisma.attribute.findMany({
|
||||
where: { teamId: organizationId },
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
options: {
|
||||
select: {
|
||||
value: true,
|
||||
},
|
||||
distinct: "value",
|
||||
},
|
||||
},
|
||||
}),
|
||||
]);
|
||||
|
||||
return {
|
||||
teams: teams,
|
||||
attributes: attributes,
|
||||
roles: [MembershipRole.OWNER, MembershipRole.ADMIN, MembershipRole.MEMBER],
|
||||
};
|
||||
};
|
||||
|
||||
export default getFacetedValuesHandler;
|
||||
@@ -1,7 +0,0 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const ZGetFacetedValuesInput = z.object({
|
||||
include: z.enum(["users", "roles", "teams", "attributes"]).array().optional(),
|
||||
});
|
||||
|
||||
export type TGetFacetedValuesInputSchema = z.infer<typeof ZGetFacetedValuesInput>;
|
||||
Reference in new issue
Block a user