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:
@@ -185,6 +185,56 @@ export const destinationCityPageSchema = z
|
||||
}
|
||||
})
|
||||
|
||||
export const cityPageUrlsSchema = z
|
||||
.object({
|
||||
all_destination_city_page: z.object({
|
||||
items: z.array(
|
||||
z
|
||||
.object({
|
||||
url: z.string(),
|
||||
destination_settings: z
|
||||
.object({
|
||||
city_denmark: z.string().optional().nullable(),
|
||||
city_finland: z.string().optional().nullable(),
|
||||
city_germany: z.string().optional().nullable(),
|
||||
city_poland: z.string().optional().nullable(),
|
||||
city_norway: z.string().optional().nullable(),
|
||||
city_sweden: z.string().optional().nullable(),
|
||||
})
|
||||
.transform(
|
||||
({
|
||||
city_denmark,
|
||||
city_finland,
|
||||
city_germany,
|
||||
city_norway,
|
||||
city_poland,
|
||||
city_sweden,
|
||||
}) => {
|
||||
const cities = [
|
||||
city_denmark,
|
||||
city_finland,
|
||||
city_germany,
|
||||
city_poland,
|
||||
city_norway,
|
||||
city_sweden,
|
||||
].filter((city): city is string => Boolean(city))
|
||||
|
||||
return { city: cities[0] }
|
||||
}
|
||||
),
|
||||
system: systemSchema,
|
||||
})
|
||||
.transform((data) => {
|
||||
return {
|
||||
city: data.destination_settings.city,
|
||||
url: removeMultipleSlashes(`/${data.system.locale}/${data.url}`),
|
||||
}
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
.transform(({ all_destination_city_page }) => all_destination_city_page.items)
|
||||
|
||||
/** REFS */
|
||||
const destinationCityPageContentRefs = z
|
||||
.object({
|
||||
|
||||
@@ -21,3 +21,13 @@ export const getDestinationCityPageSuccessCounter = meter.createCounter(
|
||||
export const getDestinationCityPageFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.destinationCityPage.get-fail"
|
||||
)
|
||||
|
||||
export const getCityPageUrlsCounter = meter.createCounter(
|
||||
"trpc.contentstack.cityPageUrls.get"
|
||||
)
|
||||
export const getCityPageUrlsSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.cityPageUrls.get-success"
|
||||
)
|
||||
export const getCityPageUrlsFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.cityPageUrls.get-fail"
|
||||
)
|
||||
|
||||
@@ -1,8 +1,21 @@
|
||||
import { GetCityPageUrls } from "@/lib/graphql/Query/DestinationCityPage/DestinationCityPageUrl.graphql"
|
||||
import { request } from "@/lib/graphql/request"
|
||||
|
||||
import { generateTag, generateTagsFromSystem } from "@/utils/generateTag"
|
||||
|
||||
import { cityPageUrlsSchema } from "./output"
|
||||
import {
|
||||
getCityPageUrlsCounter,
|
||||
getCityPageUrlsFailCounter,
|
||||
getCityPageUrlsSuccessCounter,
|
||||
} from "./telemetry"
|
||||
|
||||
import { DestinationCityPageEnum } from "@/types/enums/destinationCityPage"
|
||||
import type { System } from "@/types/requests/system"
|
||||
import type { DestinationCityPageRefs } from "@/types/trpc/routers/contentstack/destinationCityPage"
|
||||
import type {
|
||||
DestinationCityPageRefs,
|
||||
GetCityPageUrlsData,
|
||||
} from "@/types/trpc/routers/contentstack/destinationCityPage"
|
||||
import type { Lang } from "@/constants/languages"
|
||||
|
||||
export function generatePageTags(
|
||||
@@ -51,3 +64,62 @@ export function getConnections({
|
||||
|
||||
return connections
|
||||
}
|
||||
|
||||
export async function getCityPageUrls(lang: Lang) {
|
||||
getCityPageUrlsCounter.add(1, { lang })
|
||||
console.info(
|
||||
"contentstack.cityPageUrls start",
|
||||
JSON.stringify({ query: { lang } })
|
||||
)
|
||||
const tag = `${lang}:city_page_urls`
|
||||
const response = await request<GetCityPageUrlsData>(
|
||||
GetCityPageUrls,
|
||||
{
|
||||
locale: lang,
|
||||
},
|
||||
{
|
||||
cache: "force-cache",
|
||||
next: {
|
||||
tags: [tag],
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
if (!response.data) {
|
||||
getCityPageUrlsFailCounter.add(1, {
|
||||
lang,
|
||||
error_type: "not_found",
|
||||
error: `Destination city pages not found for lang: ${lang}`,
|
||||
})
|
||||
console.error(
|
||||
"contentstack.cityPageUrls not found error",
|
||||
JSON.stringify({ query: { lang } })
|
||||
)
|
||||
return []
|
||||
}
|
||||
|
||||
const validatedResponse = cityPageUrlsSchema.safeParse(response.data)
|
||||
|
||||
if (!validatedResponse.success) {
|
||||
getCityPageUrlsFailCounter.add(1, {
|
||||
lang,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedResponse.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.cityPageUrls validation error",
|
||||
JSON.stringify({
|
||||
query: { lang },
|
||||
error: validatedResponse.error,
|
||||
})
|
||||
)
|
||||
return []
|
||||
}
|
||||
getCityPageUrlsSuccessCounter.add(1, { lang })
|
||||
console.info(
|
||||
"contentstack.cityPageUrls success",
|
||||
JSON.stringify({ query: { lang } })
|
||||
)
|
||||
|
||||
return validatedResponse.data
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user