perf: migrate listHandler to AttributeRepository + cache attributes fetching in RSCs (#21552)

* refactor: migrate listHandler to AttributeRepository

Co-Authored-By: [email protected] <[email protected]>

* cache attributes list

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: [email protected] <[email protected]>
Co-authored-by: hbjORbj <[email protected]>
This commit is contained in:
authored and GitHub committed 2025-05-29 15:01:44 -04:00
1 parent c3add4bae8
commit e115095198
7 files changed
+39 -41

No files matched your search

@@ -6,6 +6,7 @@ import type { RouterOutputs } from "@calcom/trpc/react";
import { trpc } from "@calcom/trpc/react";
import { ConfirmationDialogContent } from "@calcom/ui/components/dialog";
import { showToast } from "@calcom/ui/components/toast";
import { revalidateAttributesList } from "@calcom/web/app/(use-page-wrapper)/settings/organizations/members/actions";
type AttributeItemProps = RouterOutputs["viewer"]["attributes"]["list"][number];
@@ -23,6 +24,7 @@ export function DeleteAttributeModal({
onSuccess: () => {
showToast(t("attribute_deleted_successfully"), "success");
utils.viewer.attributes.list.invalidate();
revalidateAttributesList();
},
onError: (err) => {
showToast(err.message, "error");
@@ -7,8 +7,9 @@ import { z } from "zod";
import LicenseRequired from "@calcom/features/ee/common/components/LicenseRequired";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { trpc } from "@calcom/trpc/react";
import { showToast } from "@calcom/ui/components/toast";
import { Button } from "@calcom/ui/components/button";
import { showToast } from "@calcom/ui/components/toast";
import { revalidateAttributesList } from "@calcom/web/app/(use-page-wrapper)/settings/organizations/members/actions";
import { AttributeForm } from "./AttributesForm";
@@ -37,6 +38,7 @@ function CreateAttributesPage() {
id,
});
utils.viewer.attributes.list.invalidate();
revalidateAttributesList();
},
onError: (err) => {
showToast(err.message, "error");
@@ -42,4 +42,15 @@ export class AttributeRepository {
return result;
}
static async findAllByOrgIdWithOptions({ orgId }: { orgId: number }) {
return await prisma.attribute.findMany({
where: {
teamId: orgId,
},
include: {
options: true,
},
});
}
}
@@ -1,4 +1,4 @@
import prisma from "@calcom/prisma";
import { AttributeRepository } from "@calcom/lib/server/repository/attribute";
import { TRPCError } from "@trpc/server";
@@ -20,14 +20,7 @@ const listHandler = async (opts: GetOptions) => {
});
}
return await prisma.attribute.findMany({
where: {
teamId: org.id,
},
include: {
options: true,
},
});
return await AttributeRepository.findAllByOrgIdWithOptions({ orgId: org.id });
};
export default listHandler;