Scheduling infrastructure for absolutely everyone.
perf: improve insights where query and type fix (#18211)
Alex van Andel04d7537e2f39
diff --git a/apps/web/pages/api/cron/monthlyDigestEmail.ts b/apps/web/pages/api/cron/monthlyDigestEmail.tsindex 2d00eedbb5b..dbd623abfc7 100644--- a/apps/web/pages/api/cron/monthlyDigestEmail.ts+++ b/apps/web/pages/api/cron/monthlyDigestEmail.ts@@ -158,13 +158,14 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)take: 10,});- const eventTypeIds = bookingsFromSelected- .filter((booking) => typeof booking.eventTypeId === "number")- .map((booking) => booking.eventTypeId);+ const eventTypeIds = bookingsFromSelected.reduce((acc: number[], booking) => {+ if (typeof booking.eventTypeId !== "number") return acc;+ return [...acc, booking.eventTypeId];+ }, []);const eventTypeWhereConditional: Prisma.EventTypeWhereInput = {id: {- in: eventTypeIds as number[],+ in: eventTypeIds,},};diff --git a/packages/features/insights/server/events.ts b/packages/features/insights/server/events.tsindex 19a7ea12d41..434f4ecd626 100644--- a/packages/features/insights/server/events.ts+++ b/packages/features/insights/server/events.ts@@ -483,7 +483,6 @@ class EventsInsights {// Obtain the where conditionallet whereConditional: Prisma.BookingTimeStatusWhereInput = {};- let teamConditional: Prisma.TeamWhereInput = {};if (startDate && endDate) {whereConditional.createdAt = {@@ -522,14 +521,12 @@ class EventsInsights {if (teamsFromOrg.length === 0) {return {};}- teamConditional = {- id: {- in: [organizationId, ...teamsFromOrg.map((t) => t.id)],- },- };+ const teamIds: number[] = [organizationId, ...teamsFromOrg.map((t) => t.id)];const usersFromOrg = await prisma.membership.findMany({where: {- team: teamConditional,+ teamId: {+ in: teamIds,+ },accepted: true,},select: {@@ -548,7 +545,7 @@ class EventsInsights {},{teamId: {- in: [organizationId, ...teamsFromOrg.map((t) => t.id)],+ in: teamIds,},isTeamBooking: true,},