Distributed cache * cache deleteKey now uses an options object instead of a lonely argument variable fuzzy * merge * remove debug logs and cleanup * cleanup * add fault handling * add fault handling * add pid when logging redis client creation * add identifier when logging redis client creation * cleanup * feat: add redis-api as it's own app * feature: use http wrapper for redis * feat: add the possibility to fallback to unstable_cache * Add error handling if redis cache is unresponsive * add logging for unstable_cache * merge * don't cache errors * fix: metadatabase on branchdeploys * Handle when /en/destinations throws add ErrorBoundary * Add sentry-logging when ErrorBoundary catches exception * Fix error handling for distributed cache * cleanup code * Added Application Insights back * Update generateApiKeys script and remove duplicate * Merge branch 'feature/redis' of bitbucket.org:scandic-swap/web into feature/redis * merge Approved-by: Linus Flood
97 lines
2.7 KiB
TypeScript
97 lines
2.7 KiB
TypeScript
import { batchRequest } from "@/lib/graphql/batchRequest"
|
|
import {
|
|
GetContentPage,
|
|
GetContentPageBlocksBatch1,
|
|
GetContentPageBlocksBatch2,
|
|
} from "@/lib/graphql/Query/ContentPage/ContentPage.graphql"
|
|
import { contentstackExtendedProcedureUID, router } from "@/server/trpc"
|
|
|
|
import { contentPageSchema } from "./output"
|
|
import {
|
|
createChannel,
|
|
createPageType,
|
|
fetchContentPageRefs,
|
|
generatePageTags,
|
|
getContentPageCounter,
|
|
} from "./utils"
|
|
|
|
import type { TrackingSDKPageData } from "@/types/components/tracking"
|
|
import type { GetContentPageSchema } from "@/types/trpc/routers/contentstack/contentPage"
|
|
|
|
export const contentPageQueryRouter = router({
|
|
get: contentstackExtendedProcedureUID.query(async ({ ctx }) => {
|
|
const { lang, uid } = ctx
|
|
|
|
const contentPageRefs = await fetchContentPageRefs(lang, uid)
|
|
|
|
if (!contentPageRefs) {
|
|
return null
|
|
}
|
|
|
|
const tags = generatePageTags(contentPageRefs, lang)
|
|
|
|
getContentPageCounter.add(1, { lang, uid })
|
|
console.info(
|
|
"contentstack.contentPage start",
|
|
JSON.stringify({
|
|
query: { lang, uid },
|
|
})
|
|
)
|
|
|
|
const contentPageRequest = await batchRequest<GetContentPageSchema>([
|
|
{
|
|
document: GetContentPage,
|
|
variables: { locale: lang, uid },
|
|
cacheOptions: {
|
|
key: `${tags.join(",")}:contentPage`,
|
|
ttl: "max",
|
|
},
|
|
},
|
|
|
|
{
|
|
document: GetContentPageBlocksBatch1,
|
|
variables: { locale: lang, uid },
|
|
cacheOptions: {
|
|
key: `${tags.join(",")}:contentPageBlocksBatch1`,
|
|
ttl: "max",
|
|
},
|
|
},
|
|
|
|
{
|
|
document: GetContentPageBlocksBatch2,
|
|
variables: { locale: lang, uid },
|
|
cacheOptions: {
|
|
key: `${tags.join(",")}:contentPageBlocksBatch2`,
|
|
ttl: "max",
|
|
},
|
|
},
|
|
])
|
|
|
|
const contentPage = contentPageSchema.safeParse(contentPageRequest.data)
|
|
if (!contentPage.success) {
|
|
console.error(
|
|
`Failed to validate Contentpage Data - (lang: ${lang}, uid: ${uid})`
|
|
)
|
|
console.error(contentPage.error?.format())
|
|
return null
|
|
}
|
|
|
|
const tracking: TrackingSDKPageData = {
|
|
pageId: contentPage.data.content_page.system.uid,
|
|
domainLanguage: lang,
|
|
publishDate: contentPage.data.content_page.system.updated_at,
|
|
createDate: contentPage.data.content_page.system.created_at,
|
|
channel: createChannel(contentPage.data.content_page.system.uid),
|
|
pageType: createPageType(contentPage.data.content_page.system.uid),
|
|
pageName: contentPage.data.trackingProps.url,
|
|
siteSections: contentPage.data.trackingProps.url,
|
|
siteVersion: "new-web",
|
|
}
|
|
|
|
return {
|
|
contentPage: contentPage.data.content_page,
|
|
tracking,
|
|
}
|
|
}),
|
|
})
|