fix: get bookings ordering (#18439)
* fix: get bookings ordering * chore: update query * chore: add log for debuggin on prod * chore
This commit is contained in:
@@ -2,6 +2,8 @@ import { Prisma as PrismaClientType } from "@prisma/client";
|
||||
|
||||
import { parseRecurringEvent, parseEventTypeColor } from "@calcom/lib";
|
||||
import getAllUserBookings from "@calcom/lib/bookings/getAllUserBookings";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
import { bookingMinimalSelect } from "@calcom/prisma";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
@@ -19,6 +21,8 @@ type GetOptions = {
|
||||
input: TGetInputSchema;
|
||||
};
|
||||
|
||||
const log = logger.getSubLogger({ prefix: ["bookings.get"] });
|
||||
|
||||
export const getHandler = async ({ ctx, input }: GetOptions) => {
|
||||
// using offset actually because cursor pagination requires a unique column
|
||||
// for orderBy, but we don't use a unique column in our orderBy
|
||||
@@ -471,12 +475,25 @@ export async function getBookings({
|
||||
// Now enrich bookings with relation data. We could have queried the relation data along with the bookings, but that would cause unnecessary queries to the database.
|
||||
// Because Prisma is also going to query the select relation data sequentially, we are fine querying it separately here as it would be just 1 query instead of 4
|
||||
|
||||
log.info(
|
||||
`fetching all bookings for ${user.id}`,
|
||||
safeStringify({
|
||||
ids: plainBookings.map((booking) => booking.id),
|
||||
orderBy,
|
||||
filtersCombined,
|
||||
take,
|
||||
skip,
|
||||
})
|
||||
);
|
||||
|
||||
const bookings = await Promise.all(
|
||||
(
|
||||
await prisma.booking.findMany({
|
||||
where: {
|
||||
id: {
|
||||
in: plainBookings.map((booking) => booking.id),
|
||||
in: plainBookings
|
||||
.sort((a, b) => a.startTime.getTime() - b.startTime.getTime())
|
||||
.map((booking) => booking.id),
|
||||
},
|
||||
},
|
||||
select: bookingSelect,
|
||||
|
||||
Reference in New Issue
Block a user