perf: caching + modularize data fetching for team booking pages (#22172)

* wip

* wip

* wip

* refactor

* refactor

* refactor

* refactor

* refactor

* fix

* better

* fix

* fix

* use notFound

* refactor

* wip

* refactor

* wip

* refactor

* wip

* wip

* finalize

* wip

* fix

* lots of refactors

* better code

* clean up

* fix

* fix type checks

* finalize

* select more fields

* select more fields

* fix

* fix

* fix

* fix

* better

* better

* fix

* fix

* fix

* fix

* add back comment

* fix

* better

* fix

* refactor

* fix

* fix type check

* add comment

* fix

* wip

* wip

* add more comment

* refactor

* rename

* refactors

* fix reschedule logic

* remove hard-coded true from isCachedEnabled

* better

* use revalidateTeamDataCache in team profile update

* fix invalidation

* better comment

* refactors

* add better comments

* add revalidations

* add comments

* fix

* remove hard code

* fix

* update tags

* use features package

* fix type check
This commit is contained in:
Benny Joo authored and GitHub committed 2025-07-15 21:42:55 -03:00
1 parent e6da5c85e0
commit c4eda5f21d
19 files changed
+932 -5

No files matched your search

@@ -31,6 +31,7 @@ import { TextField } from "@calcom/ui/components/form";
import { ImageUploader } from "@calcom/ui/components/image-uploader";
import { SkeletonContainer, SkeletonText } from "@calcom/ui/components/skeleton";
import { showToast } from "@calcom/ui/components/toast";
import { revalidateTeamDataCache } from "@calcom/web/app/(booking-page-wrapper)/team/[slug]/[type]/actions";
import { revalidateTeamsList } from "@calcom/web/app/(use-page-wrapper)/(main-nav)/teams/actions";
import { subdomainSuffix } from "../../../organizations/lib/orgDomains";
@@ -66,6 +67,13 @@ const OtherTeamProfileView = () => {
},
async onSuccess() {
await utils.viewer.teams.get.invalidate();
if (team?.slug) {
// Org admins editing another team's profile should purge the cached team data
revalidateTeamDataCache({
teamSlug: team.slug,
orgSlug: team.parent?.slug ?? null,
});
}
showToast(t("your_team_updated_successfully"), "success");
},
});
@@ -11,6 +11,7 @@ import { trpc } from "@calcom/trpc/react";
import { Button } from "@calcom/ui/components/button";
import { Form } from "@calcom/ui/components/form";
import { showToast } from "@calcom/ui/components/toast";
import { revalidateTeamDataCache } from "@calcom/web/app/(booking-page-wrapper)/team/[slug]/[type]/actions";
import RoundRobinResetInterval from "./RoundRobinResetInterval";
import RoundRobinTimestampBasis from "./RoundRobinTimestampBasis";
@@ -38,6 +39,13 @@ const RoundRobinSettings = ({ team }: RoundRobinSettingsProps) => {
},
async onSuccess() {
await utils.viewer.teams.get.invalidate();
if (team?.slug) {
// Rounb robin reset interval / basis governs host selection logic on the booking page.
revalidateTeamDataCache({
teamSlug: team.slug,
orgSlug: team.parent?.slug ?? null,
});
}
showToast(t("round_robin_settings_updated_successfully"), "success");
},
});
@@ -0,0 +1,48 @@
import { getSlugOrRequestedSlug } from "@calcom/features/ee/organizations/lib/orgDomains";
import { prisma } from "@calcom/prisma";
export type TeamData = Awaited<ReturnType<typeof getTeamData>>;
export async function getTeamData(teamSlug: string, orgSlug: string | null) {
return await prisma.team.findFirst({
where: {
...getSlugOrRequestedSlug(teamSlug),
parent: orgSlug ? getSlugOrRequestedSlug(orgSlug) : null,
},
orderBy: {
slug: { sort: "asc", nulls: "last" },
},
select: {
id: true,
isPrivate: true,
hideBranding: true,
parent: {
select: {
id: true,
slug: true,
name: true,
bannerUrl: true,
logoUrl: true,
hideBranding: true,
organizationSettings: {
select: {
allowSEOIndexing: true,
},
},
},
},
logoUrl: true,
name: true,
slug: true,
brandColor: true,
darkBrandColor: true,
theme: true,
isOrganization: true,
organizationSettings: {
select: {
allowSEOIndexing: true,
},
},
},
});
}
@@ -18,6 +18,7 @@ import { Button } from "@calcom/ui/components/button";
import { Form } from "@calcom/ui/components/form";
import { SettingsToggle } from "@calcom/ui/components/form";
import { showToast } from "@calcom/ui/components/toast";
import { revalidateTeamDataCache } from "@calcom/web/app/(booking-page-wrapper)/team/[slug]/[type]/actions";
import ThemeLabel from "../../../settings/ThemeLabel";
@@ -71,6 +72,14 @@ const ProfileView = ({ team }: ProfileViewProps) => {
}
showToast(t("your_team_updated_successfully"), "success");
if (res?.slug) {
// Appearance changes (theme, colours, branding toggles) are read on the team booking page through
// `getCachedTeamData` in `queries.ts`.
await revalidateTeamDataCache({
teamSlug: res?.slug,
orgSlug: team?.parent?.slug ?? null,
});
}
},
});
@@ -42,6 +42,7 @@ import {
} from "@calcom/ui/components/skeleton";
import { showToast } from "@calcom/ui/components/toast";
import { Tooltip } from "@calcom/ui/components/tooltip";
import { revalidateTeamDataCache } from "@calcom/web/app/(booking-page-wrapper)/team/[slug]/[type]/actions";
import { revalidateEventTypesList } from "@calcom/web/app/(use-page-wrapper)/(main-nav)/event-types/actions";
import { revalidateTeamsList } from "@calcom/web/app/(use-page-wrapper)/(main-nav)/teams/actions";
@@ -283,6 +284,14 @@ const TeamProfileForm = ({ team, teamId }: TeamProfileFormProps) => {
// TODO: Not all changes require list invalidation
await utils.viewer.teams.list.invalidate();
revalidateTeamsList();
if (res?.slug) {
await revalidateTeamDataCache({
teamSlug: res.slug,
orgSlug: team?.parent?.slug ?? null,
});
}
showToast(t("your_team_updated_successfully"), "success");
},
});
@@ -21,6 +21,7 @@ import { Form } from "@calcom/ui/components/form";
import { SettingsToggle } from "@calcom/ui/components/form";
import { CheckboxField } from "@calcom/ui/components/form";
import { showToast } from "@calcom/ui/components/toast";
import { revalidateTeamDataCache } from "@calcom/web/app/(booking-page-wrapper)/team/[slug]/[type]/actions";
import DisableTeamImpersonation from "../components/DisableTeamImpersonation";
import { default as InternalNotePresetsView } from "../components/InternalNotePresetsView";
@@ -57,6 +58,13 @@ const BookingLimitsView = ({ team }: ProfileViewProps) => {
includeManagedEventsInLimits: res.includeManagedEventsInLimits,
});
}
if (team?.slug) {
// Booking limits are enforced during slot generation, which relies on the same cached team data.
revalidateTeamDataCache({
teamSlug: team.slug,
orgSlug: team.parent?.slug ?? null,
});
}
showToast(t("booking_limits_updated_successfully"), "success");
},
});