perf: improve insights where query and type fix (#18211)
* perf: insights perf improvement * removed additional const
This commit is contained in:
@@ -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,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -483,7 +483,6 @@ class EventsInsights {
|
||||
|
||||
// Obtain the where conditional
|
||||
let 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,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user