fix: Reduce payload in event-type/getByViewer (#13580)
* Avoid selecting unused props * Reduce payload --------- Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
This commit is contained in:
1 parent
0e6f44e2b9
commit
34d360a4ec
6 files changed
+65
-18
No files matched your search
@@ -166,11 +166,7 @@ const Item = ({ type, group, readOnly }: { type: EventType; group: EventTypeGrou
|
||||
return readOnly ? (
|
||||
<div className="flex-1 overflow-hidden pr-4 text-sm">
|
||||
{content()}
|
||||
<EventTypeDescription
|
||||
// @ts-expect-error FIXME: We have a type mismatch here @hariombalhara @sean-brydon
|
||||
eventType={type}
|
||||
shortenDescription
|
||||
/>
|
||||
<EventTypeDescription eventType={type} shortenDescription />
|
||||
</div>
|
||||
) : (
|
||||
<Link
|
||||
@@ -197,7 +193,6 @@ const Item = ({ type, group, readOnly }: { type: EventType; group: EventTypeGrou
|
||||
)}
|
||||
</div>
|
||||
<EventTypeDescription
|
||||
// @ts-expect-error FIXME: We have a type mismatch here @hariombalhara @sean-brydon
|
||||
eventType={{ ...type, descriptionAsSafeHTML: type.safeDescription }}
|
||||
shortenDescription
|
||||
/>
|
||||
|
||||
@@ -16,11 +16,10 @@ import { Clock, Users, RefreshCw, Clipboard, Plus, User, Lock } from "@calcom/ui
|
||||
export type EventTypeDescriptionProps = {
|
||||
eventType: Pick<
|
||||
z.infer<typeof EventTypeModel>,
|
||||
Exclude<keyof typeof baseEventTypeSelect, "recurringEvent"> | "metadata"
|
||||
Exclude<keyof typeof baseEventTypeSelect, "recurringEvent"> | "metadata" | "seatsPerTimeSlot"
|
||||
> & {
|
||||
descriptionAsSafeHTML?: string | null;
|
||||
recurringEvent: Prisma.JsonValue;
|
||||
seatsPerTimeSlot?: number;
|
||||
};
|
||||
className?: string;
|
||||
shortenDescription?: boolean;
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import { Prisma } from "@calcom/prisma/client";
|
||||
|
||||
export const eventTypeSelect = Prisma.validator<Prisma.EventTypeSelect>()({
|
||||
id: true,
|
||||
teamId: true,
|
||||
schedulingType: true,
|
||||
userId: true,
|
||||
metadata: true,
|
||||
description: true,
|
||||
hidden: true,
|
||||
slug: true,
|
||||
length: true,
|
||||
title: true,
|
||||
requiresConfirmation: true,
|
||||
position: true,
|
||||
offsetStart: true,
|
||||
profileId: true,
|
||||
eventName: true,
|
||||
parentId: true,
|
||||
timeZone: true,
|
||||
periodType: true,
|
||||
periodStartDate: true,
|
||||
periodEndDate: true,
|
||||
periodDays: true,
|
||||
periodCountCalendarDays: true,
|
||||
lockTimeZoneToggleOnBookingPage: true,
|
||||
requiresBookerEmailVerification: true,
|
||||
disableGuests: true,
|
||||
hideCalendarNotes: true,
|
||||
minimumBookingNotice: true,
|
||||
beforeEventBuffer: true,
|
||||
afterEventBuffer: true,
|
||||
seatsPerTimeSlot: true,
|
||||
onlyShowFirstAvailableSlot: true,
|
||||
seatsShowAttendees: true,
|
||||
seatsShowAvailabilityCount: true,
|
||||
scheduleId: true,
|
||||
price: true,
|
||||
currency: true,
|
||||
slotInterval: true,
|
||||
successRedirectUrl: true,
|
||||
isInstantEvent: true,
|
||||
assignAllTeamMembers: true,
|
||||
recurringEvent: true,
|
||||
});
|
||||
@@ -6,6 +6,7 @@ import { prisma } from "@calcom/prisma";
|
||||
import type { Ensure } from "@calcom/types/utils";
|
||||
|
||||
import { safeStringify } from "../../safeStringify";
|
||||
import { eventTypeSelect } from "../eventTypeSelect";
|
||||
import { LookupTarget, ProfileRepository } from "./profile";
|
||||
|
||||
const log = logger.getSubLogger({ prefix: ["repository/eventType"] });
|
||||
@@ -99,12 +100,15 @@ export class EventTypeRepository {
|
||||
if (!upId) return [];
|
||||
const lookupTarget = ProfileRepository.getLookupTarget(upId);
|
||||
const profileId = lookupTarget.type === LookupTarget.User ? null : lookupTarget.id;
|
||||
const include = {
|
||||
const select = {
|
||||
...eventTypeSelect,
|
||||
// TODO: As required by getByViewHandler - Make it configurable
|
||||
team: {
|
||||
include: {
|
||||
select: {
|
||||
id: true,
|
||||
eventTypes: {
|
||||
include: {
|
||||
select: {
|
||||
id: true,
|
||||
users: { select: userSelect },
|
||||
},
|
||||
},
|
||||
@@ -140,7 +144,7 @@ export class EventTypeRepository {
|
||||
userId: lookupTarget.id,
|
||||
...where,
|
||||
},
|
||||
include,
|
||||
select,
|
||||
orderBy,
|
||||
});
|
||||
}
|
||||
@@ -164,7 +168,7 @@ export class EventTypeRepository {
|
||||
],
|
||||
...where,
|
||||
},
|
||||
include,
|
||||
select,
|
||||
orderBy,
|
||||
});
|
||||
} else {
|
||||
@@ -172,7 +176,7 @@ export class EventTypeRepository {
|
||||
where: {
|
||||
profileId,
|
||||
},
|
||||
include,
|
||||
select,
|
||||
orderBy,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { Prisma } from "@calcom/prisma/client";
|
||||
|
||||
import logger from "../../logger";
|
||||
import { safeStringify } from "../../safeStringify";
|
||||
import { eventTypeSelect } from "../eventTypeSelect";
|
||||
import { LookupTarget, ProfileRepository } from "./profile";
|
||||
|
||||
const log = logger.getSubLogger({ prefix: ["repository/membership"] });
|
||||
@@ -103,11 +104,14 @@ export class MembershipRepository {
|
||||
select: teamParentSelect,
|
||||
},
|
||||
eventTypes: {
|
||||
include: {
|
||||
select: {
|
||||
...eventTypeSelect,
|
||||
team: {
|
||||
include: {
|
||||
select: {
|
||||
id: true,
|
||||
eventTypes: {
|
||||
include: {
|
||||
select: {
|
||||
id: true,
|
||||
users: { select: userSelect },
|
||||
},
|
||||
},
|
||||
|
||||
@@ -115,7 +115,7 @@ export const getByViewerHandler = async ({ ctx, input }: GetByViewerOptions) =>
|
||||
})
|
||||
)
|
||||
),
|
||||
metadata: eventType.metadata ? EventTypeMetaDataSchema.parse(eventType.metadata) : undefined,
|
||||
metadata: eventType.metadata ? EventTypeMetaDataSchema.parse(eventType.metadata) : null,
|
||||
children: await Promise.all(
|
||||
(eventType.children || []).map(async (c) => ({
|
||||
...c,
|
||||
|
||||
Reference in new issue
Block a user