Merged in fix/SW-1819-batching-city-urls (pull request #1477)
fix(SW-1819): Batching fetch for city page urls * fix(SW-1819): Batching fetch for city page urls Approved-by: Fredrik Thorsson Approved-by: Matilda Landström
This commit is contained in:
@@ -208,9 +208,9 @@ export async function getHotelPageUrls(lang: Lang) {
|
||||
"contentstack.hotelPageUrls start",
|
||||
JSON.stringify({ query: { lang } })
|
||||
)
|
||||
const hotelPageCount = await getHotelPageCount(lang)
|
||||
const count = await getHotelPageCount(lang)
|
||||
|
||||
if (hotelPageCount === 0) {
|
||||
if (count === 0) {
|
||||
return []
|
||||
}
|
||||
|
||||
@@ -219,7 +219,7 @@ export async function getHotelPageUrls(lang: Lang) {
|
||||
// So we need to make multiple requests to fetch urls to all hotel pages.
|
||||
// The `batchRequest` function is not working here, because the arrayMerge is
|
||||
// used for other purposes.
|
||||
const amountOfRequests = Math.ceil(hotelPageCount / 100)
|
||||
const amountOfRequests = Math.ceil(count / 100)
|
||||
const requests: (BatchRequestDocument & { options?: RequestInit })[] =
|
||||
Array.from({ length: amountOfRequests }).map((_, i) => ({
|
||||
document: GetHotelPageUrls,
|
||||
@@ -238,20 +238,20 @@ export async function getHotelPageUrls(lang: Lang) {
|
||||
)
|
||||
)
|
||||
|
||||
const validatedHotelPageUrls =
|
||||
const validatedResponse =
|
||||
batchedHotelPageUrlsSchema.safeParse(batchedResponse)
|
||||
|
||||
if (!validatedHotelPageUrls.success) {
|
||||
if (!validatedResponse.success) {
|
||||
getHotelPageUrlsFailCounter.add(1, {
|
||||
lang,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedHotelPageUrls.error),
|
||||
error: JSON.stringify(validatedResponse.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.hotelPageUrls validation error",
|
||||
JSON.stringify({
|
||||
query: { lang },
|
||||
error: validatedHotelPageUrls.error,
|
||||
error: validatedResponse.error,
|
||||
})
|
||||
)
|
||||
return []
|
||||
@@ -262,5 +262,5 @@ export async function getHotelPageUrls(lang: Lang) {
|
||||
JSON.stringify({ query: { lang } })
|
||||
)
|
||||
|
||||
return validatedHotelPageUrls.data
|
||||
return validatedResponse.data
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user