fix: preload requests to avoid needing to promise.all

This commit is contained in:
Christel Westerberg
2024-10-30 16:39:04 +01:00
parent 46622d0515
commit 317619ea78
2 changed files with 36 additions and 47 deletions

View File

@@ -24,9 +24,7 @@ export default async function SummaryPage({
return notFound() return notFound()
} }
const [user, availability] = await Promise.all([ const availability = await getSelectedRoomAvailability({
getProfileSafely(),
getSelectedRoomAvailability({
hotelId: parseInt(hotel), hotelId: parseInt(hotel),
adults, adults,
children, children,
@@ -34,8 +32,8 @@ export default async function SummaryPage({
roomStayEndDate: toDate, roomStayEndDate: toDate,
rateCode, rateCode,
roomTypeCode, roomTypeCode,
}), })
]) const user = await getProfileSafely()
if (!availability) { if (!availability) {
console.error("No hotel or availability data", availability) console.error("No hotel or availability data", availability)

View File

@@ -52,37 +52,11 @@ export default async function StepPage({
toDate, toDate,
} = getQueryParamsForEnterDetails(selectRoomParams) } = getQueryParamsForEnterDetails(selectRoomParams)
void getRoomAvailability({
hotelId: parseInt(hotelId),
adults,
children,
roomStayStartDate: fromDate,
roomStayEndDate: toDate,
rateCode
})
if (!rateCode || !roomTypeCode) { if (!rateCode || !roomTypeCode) {
return notFound() return notFound()
} }
const [ void getSelectedRoomAvailability({
hotelData,
user,
savedCreditCards,
breakfastPackages,
roomAvailability,
] = await Promise.all([
getHotelData({
hotelId,
language: lang,
include: [HotelIncludeEnum.RoomCategories],
}),
getProfileSafely(),
getCreditCardsSafely(),
getBreakfastPackages(searchParams.hotel),
getSelectedRoomAvailability({
hotelId: parseInt(searchParams.hotel), hotelId: parseInt(searchParams.hotel),
adults, adults,
children, children,
@@ -90,8 +64,25 @@ export default async function StepPage({
roomStayEndDate: toDate, roomStayEndDate: toDate,
rateCode, rateCode,
roomTypeCode, roomTypeCode,
}), })
])
const hotelData = await getHotelData({
hotelId,
language: lang,
include: [HotelIncludeEnum.RoomCategories],
})
const roomAvailability = await getSelectedRoomAvailability({
hotelId: parseInt(searchParams.hotel),
adults,
children,
roomStayStartDate: fromDate,
roomStayEndDate: toDate,
rateCode,
roomTypeCode,
})
const breakfastPackages = await getBreakfastPackages(searchParams.hotel)
const user = await getProfileSafely()
const savedCreditCards = await getCreditCardsSafely()
if (!isValidStep(params.step) || !hotelData || !roomAvailability) { if (!isValidStep(params.step) || !hotelData || !roomAvailability) {
return notFound() return notFound()