Add getSchedule tests (#3233)
* Add getSchedule tests * Add first integration test * Update turbo.json * Make sure unit tests run asap * Worker threads * Improve team event test * Remove unrelated changes * Improve tests readability * Update CalendarManager.ts * Add README * Debug tests * Temporarily disabled build errors * Fix failing tests * Remove unncessary logs Co-authored-by: zomars <[email protected]>
This commit is contained in:
1 parent
2eedf74eb7
commit
471420c1d4
18 files changed
+870
-186
No files matched your search
@@ -101,20 +101,19 @@ const getCachedResults = async (
|
||||
/** We extract external Ids so we don't cache too much */
|
||||
const selectedCalendarIds = passedSelectedCalendars.map((sc) => sc.externalId);
|
||||
/** We create a unque hash key based on the input data */
|
||||
const cacheKey = createHash("md5")
|
||||
.update(JSON.stringify({ id, selectedCalendarIds, dateFrom, dateTo }))
|
||||
.digest("hex");
|
||||
const cacheKey = JSON.stringify({ id, selectedCalendarIds, dateFrom, dateTo });
|
||||
const cacheHashedKey = createHash("md5").update(cacheKey).digest("hex");
|
||||
/** Check if we already have cached data and return */
|
||||
const cachedAvailability = cache.get(cacheKey);
|
||||
const cachedAvailability = cache.get(cacheHashedKey);
|
||||
if (cachedAvailability) {
|
||||
log.debug(`Cache HIT: Calendar Availability for key`, { id, selectedCalendarIds, dateFrom, dateTo });
|
||||
log.debug(`Cache HIT: Calendar Availability for key: ${cacheKey}`);
|
||||
return cachedAvailability;
|
||||
}
|
||||
log.debug(`Cache MISS: Calendar Availability for key`, { id, selectedCalendarIds, dateFrom, dateTo });
|
||||
log.debug(`Cache MISS: Calendar Availability for key ${cacheKey}`);
|
||||
/** If we don't then we actually fetch external calendars (which can be very slow) */
|
||||
const availability = await c.getAvailability(dateFrom, dateTo, passedSelectedCalendars);
|
||||
/** We save the availability to a few seconds so recurrent calls are nearly instant */
|
||||
cache.put(cacheKey, availability, CACHING_TIME);
|
||||
cache.put(cacheHashedKey, availability, CACHING_TIME);
|
||||
return availability;
|
||||
});
|
||||
const awaitedResults = await Promise.all(results);
|
||||
|
||||
@@ -16,6 +16,13 @@ export async function getBusyTimes(params: {
|
||||
selectedCalendars: SelectedCalendar[];
|
||||
}) {
|
||||
const { credentials, userId, eventTypeId, startTime, endTime, selectedCalendars } = params;
|
||||
logger.silly(
|
||||
`Checking Busy time from Cal Bookings in range ${startTime} to ${endTime} for input ${JSON.stringify({
|
||||
userId,
|
||||
eventTypeId,
|
||||
status: BookingStatus.ACCEPTED,
|
||||
})}`
|
||||
);
|
||||
const startPrismaBookingGet = performance.now();
|
||||
const busyTimes: EventBusyDate[] = await prisma.booking
|
||||
.findMany({
|
||||
@@ -29,11 +36,13 @@ export async function getBusyTimes(params: {
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
startTime: true,
|
||||
endTime: true,
|
||||
},
|
||||
})
|
||||
.then((bookings) => bookings.map(({ startTime, endTime }) => ({ end: endTime, start: startTime })));
|
||||
logger.silly(`Busy Time from Cal Bookings ${JSON.stringify(busyTimes)}`);
|
||||
const endPrismaBookingGet = performance.now();
|
||||
logger.debug(`prisma booking get took ${endPrismaBookingGet - startPrismaBookingGet}ms`);
|
||||
if (credentials.length > 0) {
|
||||
@@ -46,7 +55,6 @@ export async function getBusyTimes(params: {
|
||||
busyTimes.push(...videoBusyTimes);
|
||||
*/
|
||||
}
|
||||
|
||||
return busyTimes;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user