Revert "perf: Refactor getPublicEvent to fetch org data using DB index key (#21850)"

This reverts commit a37f1d9798.
This commit is contained in:
Alex van Andel committed 2025-06-24 16:37:36 +01:00
1 parent 6dad0e7679
commit 218ec9140c
8 files changed
+51 -79

No files matched your search

@@ -19,7 +19,7 @@ export type useScheduleForEventReturnType = ReturnType<typeof useScheduleForEven
* of combining multiple conditional hooks.
*/
export const useEvent = (props?: { fromRedirectOfNonOrgLink?: boolean; disabled?: boolean }) => {
const [username, eventSlug, isTeamEvent, orgSlug] = useBookerStore(
const [username, eventSlug, isTeamEvent, org] = useBookerStore(
(state) => [state.username, state.eventSlug, state.isTeamEvent, state.org],
shallow
);
@@ -29,7 +29,7 @@ export const useEvent = (props?: { fromRedirectOfNonOrgLink?: boolean; disabled?
username: username ?? "",
eventSlug: eventSlug ?? "",
isTeamEvent,
orgSlug: orgSlug ?? null,
org: org ?? null,
fromRedirectOfNonOrgLink: props?.fromRedirectOfNonOrgLink,
},
{
@@ -227,20 +227,19 @@ export const getPublicEvent = async (
username: string,
eventSlug: string,
isTeamEvent: boolean | undefined,
orgSlug: string | null,
org: string | null,
prisma: PrismaClient,
fromRedirectOfNonOrgLink: boolean,
currentUserId?: number,
fetchAllUsers = false,
orgId?: number
fetchAllUsers = false
) => {
const usernameList = getUsernameList(username);
const orgQuery = orgSlug ? getSlugOrRequestedSlug(orgSlug) : null;
const orgQuery = org ? getSlugOrRequestedSlug(org) : null;
// In case of dynamic group event, we fetch user's data and use the default event.
if (usernameList.length > 1) {
const usersInOrgContext = await UserRepository.findUsersByUsername({
usernameList,
orgSlug: orgSlug,
orgSlug: org,
});
const users = usersInOrgContext;
@@ -268,27 +267,18 @@ export const getPublicEvent = async (
const disableBookingTitle = !defaultEvent.isDynamic;
const unPublishedOrgUser = users.find((user) => user.profile?.organization?.slug === null);
const orgDetails: Pick<Team, "logoUrl" | "name"> | undefined = orgId
? await prisma.team.findUniqueOrThrow({
where: {
id: orgId,
},
select: {
logoUrl: true,
name: true,
},
})
: orgSlug
? await prisma.team.findFirstOrThrow({
where: {
slug: orgSlug,
},
select: {
logoUrl: true,
name: true,
},
})
: undefined;
let orgDetails: Pick<Team, "logoUrl" | "name"> | undefined;
if (org) {
orgDetails = await prisma.team.findFirstOrThrow({
where: {
slug: org,
},
select: {
logoUrl: true,
name: true,
},
});
}
return {
...defaultEvent,
@@ -319,14 +309,14 @@ export const getPublicEvent = async (
? {
image: getPlaceholderAvatar(orgDetails?.logoUrl, orgDetails?.name),
name: orgDetails?.name,
username: orgSlug,
username: org,
}
: {}),
},
entity: {
considerUnpublished: !fromRedirectOfNonOrgLink && unPublishedOrgUser !== undefined,
fromRedirectOfNonOrgLink,
orgSlug: orgSlug,
orgSlug: org,
name: unPublishedOrgUser?.profile?.organization?.name ?? null,
teamSlug: null,
logoUrl: null,
@@ -447,28 +437,19 @@ export const getPublicEvent = async (
eventWithUserProfiles.schedule = eventOwnerDefaultSchedule;
}
const orgDetails: Pick<Team, "logoUrl" | "name"> | undefined | null = orgId
? await prisma.team.findUnique({
where: {
id: orgId,
},
select: {
logoUrl: true,
name: true,
},
})
: orgSlug
? await prisma.team.findFirst({
where: {
slug: orgSlug,
parentId: null,
},
select: {
logoUrl: true,
name: true,
},
})
: undefined;
let orgDetails: Pick<Team, "logoUrl" | "name"> | undefined | null;
if (org) {
orgDetails = await prisma.team.findFirst({
where: {
slug: org,
parentId: null,
},
select: {
logoUrl: true,
name: true,
},
});
}
let showInstantEventConnectNowModal = eventWithUserProfiles.isInstantEvent;
@@ -526,7 +507,7 @@ export const getPublicEvent = async (
(eventWithUserProfiles.team?.slug === null ||
eventWithUserProfiles.owner?.profile?.organization?.slug === null ||
eventWithUserProfiles.team?.parent?.slug === null),
orgSlug: orgSlug,
orgSlug: org,
teamSlug: (eventWithUserProfiles.team?.slug || teamMetadata?.requestedSlug) ?? null,
name:
(eventWithUserProfiles.owner?.profile?.organization?.name ||
+2 -4
View File
@@ -8,12 +8,10 @@ export class EventRepository {
input.username,
input.eventSlug,
input.isTeamEvent,
input.orgSlug,
input.org,
prisma,
input.fromRedirectOfNonOrgLink,
userId,
false,
input.orgId
userId
);
return event;
}
@@ -4,8 +4,7 @@ export const ZEventInputSchema = z.object({
username: z.string(),
eventSlug: z.string(),
isTeamEvent: z.boolean().optional(),
orgSlug: z.string().nullable(),
orgId: z.number().optional(),
org: z.string().nullable(),
/**
* Informs that the event request has been sent from a page that was reached by a redirect from non-org link(i.e. app.cal.com/username redirected to acme.cal.com/username)
* Based on this decision like whether to allow unpublished organization's event to be served or not can be made.