perf: Remove organisation as it's unused in getBusyTimes (?) (#10619)
Co-authored-by: Keith Williams <keithwillcode@gmail.com>pull/10618/head^2
parent
df674532a4
commit
2f23b5de9b
|
@ -198,8 +198,7 @@ export const getBusyCalendarTimes = async (
|
|||
withCredentials: CredentialPayload[],
|
||||
dateFrom: string,
|
||||
dateTo: string,
|
||||
selectedCalendars: SelectedCalendar[],
|
||||
organizationSlug?: string | null
|
||||
selectedCalendars: SelectedCalendar[]
|
||||
) => {
|
||||
let results: EventBusyDate[][] = [];
|
||||
const months = getMonths(dateFrom, dateTo);
|
||||
|
|
|
@ -14,7 +14,6 @@ export async function getBusyTimes(params: {
|
|||
credentials: Credential[];
|
||||
userId: number;
|
||||
username: string;
|
||||
organizationSlug?: string | null | undefined;
|
||||
eventTypeId?: number;
|
||||
startTime: string;
|
||||
beforeEventBuffer?: number;
|
||||
|
@ -30,7 +29,6 @@ export async function getBusyTimes(params: {
|
|||
eventTypeId,
|
||||
startTime,
|
||||
endTime,
|
||||
organizationSlug,
|
||||
beforeEventBuffer,
|
||||
afterEventBuffer,
|
||||
selectedCalendars,
|
||||
|
@ -165,8 +163,7 @@ export async function getBusyTimes(params: {
|
|||
credentials,
|
||||
startTime,
|
||||
endTime,
|
||||
selectedCalendars,
|
||||
organizationSlug
|
||||
selectedCalendars
|
||||
);
|
||||
const endConnectedCalendarsGet = performance.now();
|
||||
logger.debug(
|
||||
|
|
|
@ -29,7 +29,6 @@ const availabilitySchema = z
|
|||
beforeEventBuffer: z.number().optional(),
|
||||
duration: z.number().optional(),
|
||||
withSource: z.boolean().optional(),
|
||||
orgSlug: z.string().optional(),
|
||||
})
|
||||
.refine((data) => !!data.username || !!data.userId, "Either username or userId should be filled in.");
|
||||
|
||||
|
@ -77,11 +76,6 @@ const getUser = (where: Prisma.UserWhereInput) =>
|
|||
select: {
|
||||
...availabilityUserSelect,
|
||||
credentials: true,
|
||||
organization: {
|
||||
select: {
|
||||
slug: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -122,7 +116,6 @@ export async function getUserAvailability(
|
|||
afterEventBuffer?: number;
|
||||
beforeEventBuffer?: number;
|
||||
duration?: number;
|
||||
orgSlug?: string;
|
||||
},
|
||||
initialData?: {
|
||||
user?: User;
|
||||
|
@ -130,17 +123,8 @@ export async function getUserAvailability(
|
|||
currentSeats?: CurrentSeats;
|
||||
}
|
||||
) {
|
||||
const {
|
||||
username,
|
||||
userId,
|
||||
dateFrom,
|
||||
dateTo,
|
||||
eventTypeId,
|
||||
afterEventBuffer,
|
||||
beforeEventBuffer,
|
||||
duration,
|
||||
orgSlug,
|
||||
} = availabilitySchema.parse(query);
|
||||
const { username, userId, dateFrom, dateTo, eventTypeId, afterEventBuffer, beforeEventBuffer, duration } =
|
||||
availabilitySchema.parse(query);
|
||||
|
||||
if (!dateFrom.isValid() || !dateTo.isValid()) {
|
||||
throw new HttpError({ statusCode: 400, message: "Invalid time range given." });
|
||||
|
@ -148,7 +132,6 @@ export async function getUserAvailability(
|
|||
|
||||
const where: Prisma.UserWhereInput = {};
|
||||
if (username) where.username = username;
|
||||
if (orgSlug) where.organization = { slug: orgSlug };
|
||||
if (userId) where.id = userId;
|
||||
|
||||
const user = initialData?.user || (await getUser(where));
|
||||
|
@ -172,7 +155,6 @@ export async function getUserAvailability(
|
|||
eventTypeId,
|
||||
userId: user.id,
|
||||
username: `${user.username}`,
|
||||
organizationSlug: initialData?.user?.organization?.slug,
|
||||
beforeEventBuffer,
|
||||
afterEventBuffer,
|
||||
selectedCalendars: user.selectedCalendars,
|
||||
|
|
|
@ -114,26 +114,16 @@ export async function getEventType(input: TGetScheduleInputSchema) {
|
|||
isFixed: true,
|
||||
user: {
|
||||
select: {
|
||||
credentials: true, // Don't leak credentials to the client
|
||||
credentials: true,
|
||||
...availabilityUserSelect,
|
||||
organization: {
|
||||
select: {
|
||||
slug: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
users: {
|
||||
select: {
|
||||
credentials: true, // Don't leak credentials to the client
|
||||
credentials: true,
|
||||
...availabilityUserSelect,
|
||||
organization: {
|
||||
select: {
|
||||
slug: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -165,13 +155,8 @@ export async function getDynamicEventType(input: TGetScheduleInputSchema) {
|
|||
},
|
||||
select: {
|
||||
allowDynamicBooking: true,
|
||||
credentials: true, // Don't leak credentials to the client
|
||||
...availabilityUserSelect,
|
||||
organization: {
|
||||
select: {
|
||||
slug: true,
|
||||
},
|
||||
},
|
||||
credentials: true,
|
||||
},
|
||||
});
|
||||
const isDynamicAllowed = !users.some((user) => !user.allowDynamicBooking);
|
||||
|
@ -234,6 +219,7 @@ export async function getAvailableSlots(input: TGetScheduleInputSchema) {
|
|||
if (eventType.schedulingType && !!eventType.hosts?.length) {
|
||||
usersWithCredentials = eventType.hosts.map(({ isFixed, user }) => ({ isFixed, ...user }));
|
||||
}
|
||||
|
||||
/* We get all users working hours and busy slots */
|
||||
const userAvailability = await Promise.all(
|
||||
usersWithCredentials.map(async (currentUser) => {
|
||||
|
@ -255,7 +241,11 @@ export async function getAvailableSlots(input: TGetScheduleInputSchema) {
|
|||
beforeEventBuffer: eventType.beforeEventBuffer,
|
||||
duration: input.duration || 0,
|
||||
},
|
||||
{ user: currentUser, eventType, currentSeats }
|
||||
{
|
||||
user: currentUser,
|
||||
eventType,
|
||||
currentSeats,
|
||||
}
|
||||
);
|
||||
if (!currentSeats && _currentSeats) currentSeats = _currentSeats;
|
||||
return {
|
||||
|
@ -432,8 +422,7 @@ export async function getAvailableSlots(input: TGetScheduleInputSchema) {
|
|||
users: (eventType.hosts
|
||||
? eventType.hosts.map((hostUserWithCredentials) => {
|
||||
const { user } = hostUserWithCredentials;
|
||||
const { credentials: _credentials, ...hostUser } = user;
|
||||
return hostUser;
|
||||
return user;
|
||||
})
|
||||
: eventType.users
|
||||
).map((user) => user.username || ""),
|
||||
|
|
Loading…
Reference in New Issue