Merged in fix/SW-1754-overview-page-rate-limit (pull request #1412)
fix(SW-1754): Fix rate limit issue on Destination Overview Page * fix(SW-1754): Fix rate limit issue on Destination Overview Page Approved-by: Matilda Landström
This commit is contained in:
@@ -116,25 +116,23 @@ export const hotelPageRefsSchema = z.object({
|
||||
}),
|
||||
})
|
||||
|
||||
export const hotelPageUrlSchema = z
|
||||
export const hotelPageUrlsSchema = z
|
||||
.object({
|
||||
all_hotel_page: z.object({
|
||||
items: z
|
||||
.array(
|
||||
z.object({
|
||||
items: z.array(
|
||||
z
|
||||
.object({
|
||||
url: z.string(),
|
||||
hotel_page_id: z.string(),
|
||||
system: systemSchema,
|
||||
})
|
||||
)
|
||||
.max(1),
|
||||
.transform((data) => {
|
||||
return {
|
||||
url: removeMultipleSlashes(`/${data.system.locale}/${data.url}`),
|
||||
hotelId: data.hotel_page_id,
|
||||
}
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
.transform((data) => {
|
||||
const page = data.all_hotel_page.items[0]
|
||||
if (!page) {
|
||||
return null
|
||||
}
|
||||
|
||||
const lang = page.system.locale
|
||||
return removeMultipleSlashes(`/${lang}/${page.url}`)
|
||||
})
|
||||
.transform(({ all_hotel_page }) => all_hotel_page.items)
|
||||
|
||||
@@ -22,12 +22,12 @@ export const getHotelPageFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.hotelPage.get-fail"
|
||||
)
|
||||
|
||||
export const getHotelPageUrlCounter = meter.createCounter(
|
||||
"trpc.contentstack.hotelPageUrl.get"
|
||||
export const getHotelPageUrlsCounter = meter.createCounter(
|
||||
"trpc.contentstack.hotelPageUrls.get"
|
||||
)
|
||||
export const getHotelPageUrlSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.hotelPageUrl.get-success"
|
||||
export const getHotelPageUrlsSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.hotelPageUrls.get-success"
|
||||
)
|
||||
export const getHotelPageUrlFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.hotelPageUrl.get-fail"
|
||||
export const getHotelPageUrlsFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.hotelPageUrls.get-fail"
|
||||
)
|
||||
|
||||
@@ -1,29 +1,25 @@
|
||||
import { GetHotelPageRefs } from "@/lib/graphql/Query/HotelPage/HotelPage.graphql"
|
||||
import { GetHotelPageUrl } from "@/lib/graphql/Query/HotelPage/HotelPageUrl.graphql"
|
||||
import { GetHotelPageUrls } from "@/lib/graphql/Query/HotelPage/HotelPageUrl.graphql"
|
||||
import { request } from "@/lib/graphql/request"
|
||||
import { notFound } from "@/server/errors/trpc"
|
||||
|
||||
import {
|
||||
generateHotelUrlTag,
|
||||
generateTag,
|
||||
generateTagsFromSystem,
|
||||
} from "@/utils/generateTag"
|
||||
import { generateTag, generateTagsFromSystem } from "@/utils/generateTag"
|
||||
|
||||
import { hotelPageRefsSchema, hotelPageUrlSchema } from "./output"
|
||||
import { hotelPageRefsSchema, hotelPageUrlsSchema } from "./output"
|
||||
import {
|
||||
getHotelPageRefsCounter,
|
||||
getHotelPageRefsFailCounter,
|
||||
getHotelPageRefsSuccessCounter,
|
||||
getHotelPageUrlCounter,
|
||||
getHotelPageUrlFailCounter,
|
||||
getHotelPageUrlSuccessCounter,
|
||||
getHotelPageUrlsCounter,
|
||||
getHotelPageUrlsFailCounter,
|
||||
getHotelPageUrlsSuccessCounter,
|
||||
} from "./telemetry"
|
||||
|
||||
import { HotelPageEnum } from "@/types/enums/hotelPage"
|
||||
import type { System } from "@/types/requests/system"
|
||||
import type {
|
||||
GetHotelPageRefsSchema,
|
||||
GetHotelPageUrlData,
|
||||
GetHotelPageUrlsData,
|
||||
HotelPageRefs,
|
||||
} from "@/types/trpc/routers/contentstack/hotelPage"
|
||||
import type { Lang } from "@/constants/languages"
|
||||
@@ -136,63 +132,61 @@ export function getConnections({ hotel_page }: HotelPageRefs) {
|
||||
return connections
|
||||
}
|
||||
|
||||
export async function getHotelPageUrl(lang: Lang, hotelId: string) {
|
||||
getHotelPageUrlCounter.add(1, { lang, hotelId })
|
||||
export async function getHotelPageUrls(lang: Lang) {
|
||||
getHotelPageUrlsCounter.add(1, { lang })
|
||||
console.info(
|
||||
"contentstack.hotelPageUrl start",
|
||||
JSON.stringify({ query: { lang, hotelId } })
|
||||
"contentstack.hotelPageUrls start",
|
||||
JSON.stringify({ query: { lang } })
|
||||
)
|
||||
const response = await request<GetHotelPageUrlData>(
|
||||
GetHotelPageUrl,
|
||||
const tags = [`${lang}:hotel_page_urls`]
|
||||
const response = await request<GetHotelPageUrlsData>(
|
||||
GetHotelPageUrls,
|
||||
{
|
||||
locale: lang,
|
||||
hotelId,
|
||||
},
|
||||
{
|
||||
cache: "force-cache",
|
||||
next: {
|
||||
tags: [generateHotelUrlTag(lang, hotelId)],
|
||||
tags,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
if (!response.data) {
|
||||
getHotelPageUrlFailCounter.add(1, {
|
||||
getHotelPageUrlsFailCounter.add(1, {
|
||||
lang,
|
||||
hotelId,
|
||||
error_type: "not_found",
|
||||
error: `Hotel page not found for hotelId: ${hotelId}`,
|
||||
error: `Hotel pages not found for lang: ${lang}`,
|
||||
})
|
||||
console.error(
|
||||
"contentstack.hotelPageUrl not found error",
|
||||
JSON.stringify({ query: { lang, hotelId } })
|
||||
"contentstack.hotelPageUrls not found error",
|
||||
JSON.stringify({ query: { lang } })
|
||||
)
|
||||
return null
|
||||
return []
|
||||
}
|
||||
|
||||
const validatedHotelPageUrl = hotelPageUrlSchema.safeParse(response.data)
|
||||
const validatedHotelPageUrls = hotelPageUrlsSchema.safeParse(response.data)
|
||||
|
||||
if (!validatedHotelPageUrl.success) {
|
||||
getHotelPageUrlFailCounter.add(1, {
|
||||
if (!validatedHotelPageUrls.success) {
|
||||
getHotelPageUrlsFailCounter.add(1, {
|
||||
lang,
|
||||
hotelId,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedHotelPageUrl.error),
|
||||
error: JSON.stringify(validatedHotelPageUrls.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.hotelPageUrl validation error",
|
||||
"contentstack.hotelPageUrls validation error",
|
||||
JSON.stringify({
|
||||
query: { lang, hotelId },
|
||||
error: validatedHotelPageUrl.error,
|
||||
query: { lang },
|
||||
error: validatedHotelPageUrls.error,
|
||||
})
|
||||
)
|
||||
return null
|
||||
return []
|
||||
}
|
||||
getHotelPageUrlSuccessCounter.add(1, { lang, hotelId })
|
||||
getHotelPageUrlsSuccessCounter.add(1, { lang })
|
||||
console.info(
|
||||
"contentstack.hotelPageUrl success",
|
||||
JSON.stringify({ query: { lang, hotelId } })
|
||||
JSON.stringify({ query: { lang } })
|
||||
)
|
||||
|
||||
return validatedHotelPageUrl.data
|
||||
return validatedHotelPageUrls.data
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user