feat(SW-498): fixed tags for caching inside siteconfig query
This commit is contained in:
@@ -85,4 +85,7 @@ fragment AlertRef on Alert {
|
|||||||
json
|
json
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
system {
|
||||||
|
...System
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -816,6 +816,7 @@ const alertConnectionRefSchema = z.object({
|
|||||||
node: z.object({
|
node: z.object({
|
||||||
link: linkRefsSchema,
|
link: linkRefsSchema,
|
||||||
sidepeek_content: sidepeekContentRefSchema,
|
sidepeek_content: sidepeekContentRefSchema,
|
||||||
|
system: systemSchema,
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ import {
|
|||||||
getAlertPhoneContactData,
|
getAlertPhoneContactData,
|
||||||
getConnections,
|
getConnections,
|
||||||
getFooterConnections,
|
getFooterConnections,
|
||||||
|
getSiteConfigConnections,
|
||||||
} from "./utils"
|
} from "./utils"
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
@@ -630,7 +631,7 @@ export const baseQueryRouter = router({
|
|||||||
{
|
{
|
||||||
cache: "force-cache",
|
cache: "force-cache",
|
||||||
next: {
|
next: {
|
||||||
tags: [generateRefsResponseTag(lang, "siteConfig")],
|
tags: [generateRefsResponseTag(lang, "site_config")],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -676,6 +677,14 @@ export const baseQueryRouter = router({
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const connections = getSiteConfigConnections(validatedSiteConfigRef.data)
|
||||||
|
const siteConfigUid = responseRef.data.all_site_config.items[0].system.uid
|
||||||
|
|
||||||
|
const tags = [
|
||||||
|
generateTagsFromSystem(lang, connections),
|
||||||
|
generateTag(lang, siteConfigUid),
|
||||||
|
].flat()
|
||||||
|
|
||||||
getSiteConfigRefSuccessCounter.add(1, { lang })
|
getSiteConfigRefSuccessCounter.add(1, { lang })
|
||||||
console.info(
|
console.info(
|
||||||
"contentstack.siteConfig.refs success",
|
"contentstack.siteConfig.refs success",
|
||||||
@@ -695,9 +704,7 @@ export const baseQueryRouter = router({
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
cache: "force-cache",
|
cache: "force-cache",
|
||||||
next: {
|
next: { tags },
|
||||||
tags: [`${lang}:siteConfig`],
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
getContactConfig(lang),
|
getContactConfig(lang),
|
||||||
@@ -739,6 +746,7 @@ export const baseQueryRouter = router({
|
|||||||
)
|
)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
getSiteConfigSuccessCounter.add(1, { lang })
|
getSiteConfigSuccessCounter.add(1, { lang })
|
||||||
console.info(
|
console.info(
|
||||||
"contentstack.siteConfig success",
|
"contentstack.siteConfig success",
|
||||||
|
|||||||
@@ -5,7 +5,10 @@ import type { System } from "@/types/requests/system"
|
|||||||
import type { Edges } from "@/types/requests/utils/edges"
|
import type { Edges } from "@/types/requests/utils/edges"
|
||||||
import type { NodeRefs } from "@/types/requests/utils/refs"
|
import type { NodeRefs } from "@/types/requests/utils/refs"
|
||||||
import type { HeaderRefs } from "@/types/trpc/routers/contentstack/header"
|
import type { HeaderRefs } from "@/types/trpc/routers/contentstack/header"
|
||||||
import type { AlertOutput } from "@/types/trpc/routers/contentstack/siteConfig"
|
import type {
|
||||||
|
AlertOutput,
|
||||||
|
GetSiteConfigRefData,
|
||||||
|
} from "@/types/trpc/routers/contentstack/siteConfig"
|
||||||
import type { ContactConfig } from "./output"
|
import type { ContactConfig } from "./output"
|
||||||
|
|
||||||
export function getConnections({ header }: HeaderRefs) {
|
export function getConnections({ header }: HeaderRefs) {
|
||||||
@@ -70,6 +73,29 @@ export function getFooterConnections(refs: FooterRefDataRaw) {
|
|||||||
return connections
|
return connections
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getSiteConfigConnections(refs: GetSiteConfigRefData) {
|
||||||
|
const siteConfigData = refs.all_site_config.items[0]
|
||||||
|
const connections: System["system"][] = []
|
||||||
|
|
||||||
|
const alertConnection = siteConfigData.sitewide_alert.alertConnection
|
||||||
|
|
||||||
|
alertConnection.edges.forEach(({ node }) => {
|
||||||
|
connections.push(node.system)
|
||||||
|
|
||||||
|
const link = node.link.link
|
||||||
|
if (link) {
|
||||||
|
connections.push(link)
|
||||||
|
}
|
||||||
|
node.sidepeek_content.content.embedded_itemsConnection.edges.forEach(
|
||||||
|
({ node }) => {
|
||||||
|
connections.push(node.system)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
return connections
|
||||||
|
}
|
||||||
|
|
||||||
export function getAlertPhoneContactData(
|
export function getAlertPhoneContactData(
|
||||||
alert: AlertOutput,
|
alert: AlertOutput,
|
||||||
contactConfig: ContactConfig
|
contactConfig: ContactConfig
|
||||||
|
|||||||
Reference in New Issue
Block a user