perf: reduce array iteration on bookings router (#8276)

This commit is contained in:
Yagiz Nizipli
2023-04-14 21:29:43 +00:00
committed by GitHub
parent f7df204e0b
commit 5339a489f5
@@ -339,17 +339,17 @@ export const bookingsRouter = router({
[key: string]: Date[];
};
} => {
const bookings = recurringInfoExtended
.filter((ext) => ext.recurringEventId === info.recurringEventId)
.reduce(
(prev, curr) => {
const bookings = recurringInfoExtended.reduce(
(prev, curr) => {
if (curr.recurringEventId === info.recurringEventId) {
prev[curr.status].push(curr.startTime);
return prev;
},
{ ACCEPTED: [], CANCELLED: [], REJECTED: [], PENDING: [] } as {
[key in BookingStatus]: Date[];
}
);
return prev;
},
{ ACCEPTED: [], CANCELLED: [], REJECTED: [], PENDING: [] } as {
[key in BookingStatus]: Date[];
}
);
return {
recurringEventId: info.recurringEventId,
count: info._count.recurringEventId,
@@ -548,8 +548,8 @@ export const bookingsRouter = router({
user.credentials.forEach((credential) => {
credentialsMap.set(credential.type, credential);
});
const bookingRefsFiltered: BookingReference[] = bookingToReschedule.references.filter(
(ref) => !!credentialsMap.get(ref.type)
const bookingRefsFiltered: BookingReference[] = bookingToReschedule.references.filter((ref) =>
credentialsMap.has(ref.type)
);
bookingRefsFiltered.forEach(async (bookingRef) => {
if (bookingRef.uid) {