Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: don't fetch all the hosts [DO NOT MERGE] #18319

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/web/app/d/[link]/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const generateMetadata = async ({ params, searchParams }: _PageProps) =>
isTeamEvent,
org,
fromRedirectOfNonOrgLink: legacyCtx.query.orgRedirection === "true",
limitHostsToThree: true,
});

const profileName = event?.profile?.name ?? "";
Expand Down
1 change: 1 addition & 0 deletions apps/web/app/future/[user]/[type]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const generateMetadata = async ({ params, searchParams }: PageProps) => {
isTeamEvent: false,
org: isValidOrgDomain ? currentOrgDomain : null,
fromRedirectOfNonOrgLink: legacyCtx.query.orgRedirection === "true",
limitHostsToThree: true,
});

const profileName = event?.profile?.name ?? "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const generateMetadata = async ({ params, searchParams }: _PageProps) =>
isTeamEvent: true,
org,
fromRedirectOfNonOrgLink: context.query.orgRedirection === "true",
limitHostsToThree: true,
});

const profileName = event?.profile.name ?? "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const generateMetadata = async ({ params, searchParams }: _PageProps) =>
isTeamEvent: true,
org: isValidOrgDomain ? currentOrgDomain : null,
fromRedirectOfNonOrgLink: legacyCtx.query.orgRedirection === "true",
limitHostsToThree: true,
});

const profileName = event?.profile?.name ?? "";
Expand Down
1 change: 1 addition & 0 deletions apps/web/app/future/team/[slug]/[type]/embed/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const generateMetadata = async ({ params, searchParams }: _PageProps) =>
isTeamEvent: true,
org: isValidOrgDomain ? currentOrgDomain : null,
fromRedirectOfNonOrgLink: legacyCtx.query.orgRedirection === "true",
limitHostsToThree: true,
});

const profileName = event?.profile?.name ?? "";
Expand Down
1 change: 1 addition & 0 deletions apps/web/app/future/team/[slug]/[type]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const generateMetadata = async ({ params, searchParams }: PageProps) => {
isTeamEvent: true,
org: isValidOrgDomain ? currentOrgDomain : null,
fromRedirectOfNonOrgLink: legacyCtx.query.orgRedirection === "true",
limitHostsToThree: true,
});

const profileName = event?.profile?.name ?? "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { FromTime } from "../../utils/dates";
import { useEvent } from "../../utils/event";

const BookEventFormWrapper = ({ children, onCancel }: { onCancel: () => void; children: ReactNode }) => {
const { data } = useEvent();
const { data } = useEvent({ limitHostsToThree: true });

return <BookEventFormWrapperComponent child={children} eventLength={data?.length} onCancel={onCancel} />;
};
Expand Down
3 changes: 2 additions & 1 deletion packages/features/bookings/Booker/utils/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type useScheduleForEventReturnType = ReturnType<typeof useScheduleForEven
* Using this hook means you only need to use one hook, instead
* of combining multiple conditional hooks.
*/
export const useEvent = (props?: { fromRedirectOfNonOrgLink?: boolean }) => {
export const useEvent = (props?: { fromRedirectOfNonOrgLink?: boolean; limitHostsToThree?: boolean }) => {
const [username, eventSlug, isTeamEvent, org] = useBookerStore(
(state) => [state.username, state.eventSlug, state.isTeamEvent, state.org],
shallow
Expand All @@ -32,6 +32,7 @@ export const useEvent = (props?: { fromRedirectOfNonOrgLink?: boolean }) => {
isTeamEvent,
org: org ?? null,
fromRedirectOfNonOrgLink: props?.fromRedirectOfNonOrgLink,
limitHostsToThree: props?.limitHostsToThree,
},
{
refetchOnWindowFocus: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/features/embed/Embed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ const EmailEmbed = ({
],
shallow
);
const event = useEvent();
const event = useEvent({ limitHostsToThree: true });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need all the hosts on the front end

const schedule = useScheduleForEvent({ orgSlug, eventId: eventType?.id, isTeamEvent });
const nonEmptyScheduleDays = useNonEmptyScheduleDays(schedule?.data?.slots);

Expand Down
195 changes: 100 additions & 95 deletions packages/features/eventtypes/lib/getPublicEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,99 +50,6 @@ const userSelect = Prisma.validator<Prisma.UserSelect>()({
defaultScheduleId: true,
});

const publicEventSelect = Prisma.validator<Prisma.EventTypeSelect>()({
id: true,
title: true,
description: true,
eventName: true,
slug: true,
isInstantEvent: true,
instantMeetingParameters: true,
aiPhoneCallConfig: true,
schedulingType: true,
length: true,
locations: true,
customInputs: true,
disableGuests: true,
metadata: true,
lockTimeZoneToggleOnBookingPage: true,
requiresConfirmation: true,
autoTranslateDescriptionEnabled: true,
fieldTranslations: {
select: {
translatedText: true,
targetLocale: true,
field: true,
},
},
requiresBookerEmailVerification: true,
recurringEvent: true,
price: true,
currency: true,
seatsPerTimeSlot: true,
seatsShowAvailabilityCount: true,
bookingFields: true,
teamId: true,
team: {
select: {
parentId: true,
metadata: true,
brandColor: true,
darkBrandColor: true,
slug: true,
name: true,
logoUrl: true,
theme: true,
parent: {
select: {
slug: true,
name: true,
bannerUrl: true,
logoUrl: true,
},
},
isPrivate: true,
},
},
successRedirectUrl: true,
forwardParamsSuccessRedirect: true,
workflows: {
include: {
workflow: {
include: {
steps: true,
},
},
},
},
hosts: {
select: {
user: {
select: userSelect,
},
},
},
owner: {
select: userSelect,
},
schedule: {
select: {
id: true,
timeZone: true,
},
},
instantMeetingSchedule: {
select: {
id: true,
timeZone: true,
},
},

hidden: true,
assignAllTeamMembers: true,
rescheduleWithSameRoundRobinHost: true,
});

export async function isCurrentlyAvailable({
prisma,
instantMeetingScheduleId,
Expand Down Expand Up @@ -209,6 +116,102 @@ function isAvailableInTimeSlot(
return isWithinPeriod;
}

const getPublicEventSelect = (limitHostsToThree?: boolean) => {
return Prisma.validator<Prisma.EventTypeSelect>()({
id: true,
title: true,
description: true,
eventName: true,
slug: true,
isInstantEvent: true,
instantMeetingParameters: true,
aiPhoneCallConfig: true,
schedulingType: true,
length: true,
locations: true,
customInputs: true,
disableGuests: true,
metadata: true,
lockTimeZoneToggleOnBookingPage: true,
requiresConfirmation: true,
autoTranslateDescriptionEnabled: true,
fieldTranslations: {
select: {
translatedText: true,
targetLocale: true,
field: true,
},
},
requiresBookerEmailVerification: true,
recurringEvent: true,
price: true,
currency: true,
seatsPerTimeSlot: true,
seatsShowAvailabilityCount: true,
bookingFields: true,
teamId: true,
team: {
select: {
parentId: true,
metadata: true,
brandColor: true,
darkBrandColor: true,
slug: true,
name: true,
logoUrl: true,
theme: true,
parent: {
select: {
slug: true,
name: true,
bannerUrl: true,
logoUrl: true,
},
},
isPrivate: true,
},
},
successRedirectUrl: true,
forwardParamsSuccessRedirect: true,
workflows: {
include: {
workflow: {
include: {
steps: true,
},
},
},
},
hosts: {
select: {
user: {
select: userSelect,
},
},
...(limitHostsToThree ? { take: 3 } : {}),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would still need all the hosts for single event type page so we don't want the limit everytime

},
owner: {
select: userSelect,
},
schedule: {
select: {
id: true,
timeZone: true,
},
},
instantMeetingSchedule: {
select: {
id: true,
timeZone: true,
},
},

hidden: true,
assignAllTeamMembers: true,
rescheduleWithSameRoundRobinHost: true,
});
};

// TODO: Convert it to accept a single parameter with structured data
export const getPublicEvent = async (
username: string,
Expand All @@ -217,8 +220,10 @@ export const getPublicEvent = async (
org: string | null,
prisma: PrismaClient,
fromRedirectOfNonOrgLink: boolean,
currentUserId?: number
currentUserId?: number,
limitHostsToThree?: boolean
) => {
const publicEventSelect = getPublicEventSelect(limitHostsToThree);
const usernameList = getUsernameList(username);
const orgQuery = org ? getSlugOrRequestedSlug(org) : null;
// In case of dynamic group event, we fetch user's data and use the default event.
Expand Down Expand Up @@ -504,7 +509,7 @@ export const getPublicEvent = async (
};

const eventData = Prisma.validator<Prisma.EventTypeArgs>()({
select: publicEventSelect,
select: getPublicEventSelect(false),
});

type Event = Prisma.EventTypeGetPayload<typeof eventData>;
Expand Down
3 changes: 2 additions & 1 deletion packages/lib/server/repository/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export class EventRepository {
input.org,
prisma,
input.fromRedirectOfNonOrgLink,
userId
userId,
input.limitHostsToThree
);
return event;
}
Expand Down
5 changes: 4 additions & 1 deletion packages/platform/atoms/booker/BookerWebWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ export const BookerWebWrapper = (props: BookerWebWrapperAtomProps) => {
const router = useRouter();
const pathname = usePathname();
const searchParams = useSearchParams();
const event = useEvent({ fromRedirectOfNonOrgLink: props.entity.fromRedirectOfNonOrgLink });
const event = useEvent({
fromRedirectOfNonOrgLink: props.entity.fromRedirectOfNonOrgLink,
limitHostsToThree: true,
});
const bookerLayout = useBookerLayout(event.data);

const selectedDate = searchParams?.get("date");
Expand Down
1 change: 1 addition & 0 deletions packages/trpc/server/routers/publicViewer/event.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const ZEventInputSchema = z.object({
* Based on this decision like whether to allow unpublished organization's event to be served or not can be made.
*/
fromRedirectOfNonOrgLink: z.boolean().optional().default(false),
limitHostsToThree: z.boolean().optional().default(false),
});

export type TEventInputSchema = z.infer<typeof ZEventInputSchema>;
Loading