perf: Remove organisation as it's unused in getBusyTimes (?) (#10619)

Co-authored-by: Keith Williams <keithwillcode@gmail.com>
This commit is contained in:
Alex van Andel 2023-08-07 15:06:48 +01:00 committed by GitHub
parent df674532a4
commit 2f23b5de9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 47 deletions

View File

@ -198,8 +198,7 @@ export const getBusyCalendarTimes = async (
withCredentials: CredentialPayload[], withCredentials: CredentialPayload[],
dateFrom: string, dateFrom: string,
dateTo: string, dateTo: string,
selectedCalendars: SelectedCalendar[], selectedCalendars: SelectedCalendar[]
organizationSlug?: string | null
) => { ) => {
let results: EventBusyDate[][] = []; let results: EventBusyDate[][] = [];
const months = getMonths(dateFrom, dateTo); const months = getMonths(dateFrom, dateTo);

View File

@ -14,7 +14,6 @@ export async function getBusyTimes(params: {
credentials: Credential[]; credentials: Credential[];
userId: number; userId: number;
username: string; username: string;
organizationSlug?: string | null | undefined;
eventTypeId?: number; eventTypeId?: number;
startTime: string; startTime: string;
beforeEventBuffer?: number; beforeEventBuffer?: number;
@ -30,7 +29,6 @@ export async function getBusyTimes(params: {
eventTypeId, eventTypeId,
startTime, startTime,
endTime, endTime,
organizationSlug,
beforeEventBuffer, beforeEventBuffer,
afterEventBuffer, afterEventBuffer,
selectedCalendars, selectedCalendars,
@ -165,8 +163,7 @@ export async function getBusyTimes(params: {
credentials, credentials,
startTime, startTime,
endTime, endTime,
selectedCalendars, selectedCalendars
organizationSlug
); );
const endConnectedCalendarsGet = performance.now(); const endConnectedCalendarsGet = performance.now();
logger.debug( logger.debug(

View File

@ -29,7 +29,6 @@ const availabilitySchema = z
beforeEventBuffer: z.number().optional(), beforeEventBuffer: z.number().optional(),
duration: z.number().optional(), duration: z.number().optional(),
withSource: z.boolean().optional(), withSource: z.boolean().optional(),
orgSlug: z.string().optional(),
}) })
.refine((data) => !!data.username || !!data.userId, "Either username or userId should be filled in."); .refine((data) => !!data.username || !!data.userId, "Either username or userId should be filled in.");
@ -77,11 +76,6 @@ const getUser = (where: Prisma.UserWhereInput) =>
select: { select: {
...availabilityUserSelect, ...availabilityUserSelect,
credentials: true, credentials: true,
organization: {
select: {
slug: true,
},
},
}, },
}); });
@ -122,7 +116,6 @@ export async function getUserAvailability(
afterEventBuffer?: number; afterEventBuffer?: number;
beforeEventBuffer?: number; beforeEventBuffer?: number;
duration?: number; duration?: number;
orgSlug?: string;
}, },
initialData?: { initialData?: {
user?: User; user?: User;
@ -130,17 +123,8 @@ export async function getUserAvailability(
currentSeats?: CurrentSeats; currentSeats?: CurrentSeats;
} }
) { ) {
const { const { username, userId, dateFrom, dateTo, eventTypeId, afterEventBuffer, beforeEventBuffer, duration } =
username, availabilitySchema.parse(query);
userId,
dateFrom,
dateTo,
eventTypeId,
afterEventBuffer,
beforeEventBuffer,
duration,
orgSlug,
} = availabilitySchema.parse(query);
if (!dateFrom.isValid() || !dateTo.isValid()) { if (!dateFrom.isValid() || !dateTo.isValid()) {
throw new HttpError({ statusCode: 400, message: "Invalid time range given." }); throw new HttpError({ statusCode: 400, message: "Invalid time range given." });
@ -148,7 +132,6 @@ export async function getUserAvailability(
const where: Prisma.UserWhereInput = {}; const where: Prisma.UserWhereInput = {};
if (username) where.username = username; if (username) where.username = username;
if (orgSlug) where.organization = { slug: orgSlug };
if (userId) where.id = userId; if (userId) where.id = userId;
const user = initialData?.user || (await getUser(where)); const user = initialData?.user || (await getUser(where));
@ -172,7 +155,6 @@ export async function getUserAvailability(
eventTypeId, eventTypeId,
userId: user.id, userId: user.id,
username: `${user.username}`, username: `${user.username}`,
organizationSlug: initialData?.user?.organization?.slug,
beforeEventBuffer, beforeEventBuffer,
afterEventBuffer, afterEventBuffer,
selectedCalendars: user.selectedCalendars, selectedCalendars: user.selectedCalendars,

View File

@ -114,26 +114,16 @@ export async function getEventType(input: TGetScheduleInputSchema) {
isFixed: true, isFixed: true,
user: { user: {
select: { select: {
credentials: true, // Don't leak credentials to the client credentials: true,
...availabilityUserSelect, ...availabilityUserSelect,
organization: {
select: {
slug: true,
},
},
}, },
}, },
}, },
}, },
users: { users: {
select: { select: {
credentials: true, // Don't leak credentials to the client credentials: true,
...availabilityUserSelect, ...availabilityUserSelect,
organization: {
select: {
slug: true,
},
},
}, },
}, },
}, },
@ -165,13 +155,8 @@ export async function getDynamicEventType(input: TGetScheduleInputSchema) {
}, },
select: { select: {
allowDynamicBooking: true, allowDynamicBooking: true,
credentials: true, // Don't leak credentials to the client
...availabilityUserSelect, ...availabilityUserSelect,
organization: { credentials: true,
select: {
slug: true,
},
},
}, },
}); });
const isDynamicAllowed = !users.some((user) => !user.allowDynamicBooking); const isDynamicAllowed = !users.some((user) => !user.allowDynamicBooking);
@ -234,6 +219,7 @@ export async function getAvailableSlots(input: TGetScheduleInputSchema) {
if (eventType.schedulingType && !!eventType.hosts?.length) { if (eventType.schedulingType && !!eventType.hosts?.length) {
usersWithCredentials = eventType.hosts.map(({ isFixed, user }) => ({ isFixed, ...user })); usersWithCredentials = eventType.hosts.map(({ isFixed, user }) => ({ isFixed, ...user }));
} }
/* We get all users working hours and busy slots */ /* We get all users working hours and busy slots */
const userAvailability = await Promise.all( const userAvailability = await Promise.all(
usersWithCredentials.map(async (currentUser) => { usersWithCredentials.map(async (currentUser) => {
@ -255,7 +241,11 @@ export async function getAvailableSlots(input: TGetScheduleInputSchema) {
beforeEventBuffer: eventType.beforeEventBuffer, beforeEventBuffer: eventType.beforeEventBuffer,
duration: input.duration || 0, duration: input.duration || 0,
}, },
{ user: currentUser, eventType, currentSeats } {
user: currentUser,
eventType,
currentSeats,
}
); );
if (!currentSeats && _currentSeats) currentSeats = _currentSeats; if (!currentSeats && _currentSeats) currentSeats = _currentSeats;
return { return {
@ -432,8 +422,7 @@ export async function getAvailableSlots(input: TGetScheduleInputSchema) {
users: (eventType.hosts users: (eventType.hosts
? eventType.hosts.map((hostUserWithCredentials) => { ? eventType.hosts.map((hostUserWithCredentials) => {
const { user } = hostUserWithCredentials; const { user } = hostUserWithCredentials;
const { credentials: _credentials, ...hostUser } = user; return user;
return hostUser;
}) })
: eventType.users : eventType.users
).map((user) => user.username || ""), ).map((user) => user.username || ""),