Add logs (#3256)
This commit is contained in:
1 parent
f9cc71d120
commit
5db762e987
5 files changed
+58
-17
No files matched your search
@@ -78,7 +78,7 @@ export const getConnectedCalendars = async (
|
||||
|
||||
const CACHING_TIME = 30_000; // 30 seconds
|
||||
|
||||
const getCachedResults = (
|
||||
const getCachedResults = async (
|
||||
withCredentials: Credential[],
|
||||
dateFrom: string,
|
||||
dateTo: string,
|
||||
@@ -86,6 +86,8 @@ const getCachedResults = (
|
||||
) => {
|
||||
const calendarCredentials = withCredentials.filter((credential) => credential.type.endsWith("_calendar"));
|
||||
const calendars = calendarCredentials.map((credential) => getCalendar(credential));
|
||||
|
||||
const startGetBusyCalendarTimes = performance.now();
|
||||
const results = calendars.map(async (c, i) => {
|
||||
/** Filter out nulls */
|
||||
if (!c) return [];
|
||||
@@ -103,15 +105,26 @@ const getCachedResults = (
|
||||
.digest("hex");
|
||||
/** Check if we already have cached data and return */
|
||||
const cachedAvailability = cache.get(cacheKey);
|
||||
if (cachedAvailability) return cachedAvailability;
|
||||
if (cachedAvailability) {
|
||||
log.debug(`Cache HIT: Calendar Availability for key`, { id, selectedCalendarIds, dateFrom, dateTo });
|
||||
return cachedAvailability;
|
||||
}
|
||||
log.debug(`Cache MISS: Calendar Availability for key`, { id, selectedCalendarIds, dateFrom, dateTo });
|
||||
/** 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);
|
||||
return availability;
|
||||
});
|
||||
const awaitedResults = await Promise.all(results);
|
||||
const endGetBusyCalendarTimes = performance.now();
|
||||
|
||||
return Promise.all(results);
|
||||
log.debug(
|
||||
`getBusyCalendarTimes took ${
|
||||
endGetBusyCalendarTimes - startGetBusyCalendarTimes
|
||||
}ms for creds ${calendarCredentials.map((cred) => cred.id)}`
|
||||
);
|
||||
return awaitedResults;
|
||||
};
|
||||
|
||||
export const getBusyCalendarTimes = async (
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { BookingStatus, Credential, SelectedCalendar } from "@prisma/client";
|
||||
|
||||
import { getBusyCalendarTimes } from "@calcom/core/CalendarManager";
|
||||
import logger from "@calcom/lib/logger";
|
||||
// import { getBusyVideoTimes } from "@calcom/core/videoClient";
|
||||
// import notEmpty from "@calcom/lib/notEmpty";
|
||||
import prisma from "@calcom/prisma";
|
||||
@@ -15,6 +16,7 @@ export async function getBusyTimes(params: {
|
||||
selectedCalendars: SelectedCalendar[];
|
||||
}) {
|
||||
const { credentials, userId, eventTypeId, startTime, endTime, selectedCalendars } = params;
|
||||
const startPrismaBookingGet = performance.now();
|
||||
const busyTimes: EventBusyDate[] = await prisma.booking
|
||||
.findMany({
|
||||
where: {
|
||||
@@ -32,7 +34,8 @@ export async function getBusyTimes(params: {
|
||||
},
|
||||
})
|
||||
.then((bookings) => bookings.map(({ startTime, endTime }) => ({ end: endTime, start: startTime })));
|
||||
|
||||
const endPrismaBookingGet = performance.now();
|
||||
logger.debug(`prisma booking get took ${endPrismaBookingGet - startPrismaBookingGet}ms`);
|
||||
if (credentials.length > 0) {
|
||||
const calendarBusyTimes = await getBusyCalendarTimes(credentials, startTime, endTime, selectedCalendars);
|
||||
// console.log("calendarBusyTimes", calendarBusyTimes);
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { Prisma } from "@prisma/client";
|
||||
import dayjs, { Dayjs } from "@calcom/dayjs";
|
||||
import { z } from "zod";
|
||||
|
||||
import dayjs, { Dayjs } from "@calcom/dayjs";
|
||||
import { getWorkingHours } from "@calcom/lib/availability";
|
||||
import { HttpError } from "@calcom/lib/http-error";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import prisma, { availabilityUserSelect } from "@calcom/prisma";
|
||||
import { stringToDayjs } from "@calcom/prisma/zod-utils";
|
||||
|
||||
@@ -137,13 +138,14 @@ export async function getUserAvailability(
|
||||
};
|
||||
|
||||
const timeZone = timezone || schedule?.timeZone || eventType?.timeZone || currentUser.timeZone;
|
||||
|
||||
const startGetWorkingHours = performance.now();
|
||||
const workingHours = getWorkingHours(
|
||||
{ timeZone },
|
||||
schedule.availability ||
|
||||
(eventType?.availability.length ? eventType.availability : currentUser.availability)
|
||||
);
|
||||
|
||||
const endGetWorkingHours = performance.now();
|
||||
logger.debug(`getWorkingHours took ${endGetWorkingHours - startGetWorkingHours}ms for userId ${userId}`);
|
||||
return {
|
||||
busy: bufferedBusyTimes,
|
||||
timeZone,
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Logger } from "tslog";
|
||||
import { IS_PRODUCTION } from "./constants";
|
||||
|
||||
const logger = new Logger({
|
||||
minLevel: "info",
|
||||
dateTimePattern: "hour:minute:second.millisecond timeZoneName",
|
||||
displayFunctionName: false,
|
||||
displayFilePath: "hidden",
|
||||
|
||||
Reference in new issue
Block a user