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,18 +24,16 @@ export default async function SummaryPage({
return notFound()
}
const [user, availability] = await Promise.all([
getProfileSafely(),
getSelectedRoomAvailability({
hotelId: parseInt(hotel),
adults,
children,
roomStayStartDate: fromDate,
roomStayEndDate: toDate,
rateCode,
roomTypeCode,
}),
])
const availability = await getSelectedRoomAvailability({
hotelId: parseInt(hotel),
adults,
children,
roomStayStartDate: fromDate,
roomStayEndDate: toDate,
rateCode,
roomTypeCode,
})
const user = await getProfileSafely()
if (!availability) {
console.error("No hotel or availability data", availability)

View File

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