Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ETL staging server MDim caching issues #4296

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion adminSiteServer/adminRouter.tsx
Original file line number Diff line number Diff line change
@@ -363,7 +363,8 @@ getPlainRouteWithROTransaction(
const renderedPage = await renderMultiDimDataPageFromConfig(
trx,
slug,
mdd.config
mdd.config,
true
)
res.send(renderedPage)
return
4 changes: 3 additions & 1 deletion baker/MultiDimBaker.tsx
Original file line number Diff line number Diff line change
@@ -119,7 +119,8 @@ const getFaqEntries = async (
export const renderMultiDimDataPageFromConfig = async (
knex: db.KnexReadonlyTransaction,
slug: string,
config: MultiDimDataPageConfigEnriched
config: MultiDimDataPageConfigEnriched,
isPreviewing: boolean = false
) => {
// TAGS
const tagToSlugMap = await getTagToSlugMap(knex)
@@ -142,6 +143,7 @@ export const renderMultiDimDataPageFromConfig = async (
tagToSlugMap: minimalTagToSlugMap,
faqEntries,
primaryTopic,
isPreviewing,
}

return renderMultiDimDataPageFromProps(props)
2 changes: 1 addition & 1 deletion functions/grapher/[slug].ts
Original file line number Diff line number Diff line change
@@ -186,7 +186,7 @@ async function handleConfigRequest(
}

const cacheControl = shouldCache
? "s-maxage=3600, max-age=0, must-revalidate"
? "s-maxage=300, max-age=0, must-revalidate"
: "no-cache"

//grapherPageResp.headers.set("Cache-Control", cacheControl)
2 changes: 1 addition & 1 deletion functions/grapher/by-uuid/[uuid].ts
Original file line number Diff line number Diff line change
@@ -87,7 +87,7 @@ async function handleConfigRequest(
console.log("Grapher page response", grapherPageResp.grapherConfig.title)

const cacheControl = shouldCache
? "s-maxage=3600, max-age=0, must-revalidate"
? "s-maxage=300, max-age=0, must-revalidate"
: "no-cache"

return Response.json(grapherPageResp.grapherConfig, {
2 changes: 1 addition & 1 deletion functions/multi-dim/[slug].json.ts
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ export const onRequestGet: PagesFunction<Env> = async ({
}

const cacheControl = shouldCache
? "s-maxage=3600, max-age=0, must-revalidate"
? "s-maxage=300, max-age=0, must-revalidate"
: "no-cache"

return new Response(grapherPageResp.body, {
2 changes: 2 additions & 0 deletions site/multiDim/MultiDimDataPage.tsx
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ export function MultiDimDataPage({
faqEntries,
primaryTopic,
initialQueryStr,
isPreviewing,
}: MultiDimDataPageProps) {
const canonicalUrl = `${baseGrapherUrl}/${slug}`
const contentProps: MultiDimDataPageContentProps = {
@@ -81,6 +82,7 @@ export function MultiDimDataPage({
<SiteFooter
baseUrl={baseUrl}
context={SiteFooterContext.multiDimDataPage}
isPreviewing={isPreviewing}
/>
</body>
</Html>
20 changes: 13 additions & 7 deletions site/multiDim/MultiDimDataPageContent.tsx
Original file line number Diff line number Diff line change
@@ -108,10 +108,14 @@ const cachedGetVariableMetadata = memoize(
)

const cachedGetGrapherConfigByUuid = memoize(
(grapherConfigUuid: string): Promise<GrapherInterface> =>
fetchWithRetry(
`/grapher/by-uuid/${grapherConfigUuid}.config.json`
(
grapherConfigUuid: string,
isPreviewing: boolean
): Promise<GrapherInterface> => {
return fetchWithRetry(
`/grapher/by-uuid/${grapherConfigUuid}.config.json${isPreviewing ? "?nocache" : ""}`
).then((resp) => resp.json())
}
)

const useTitleFragments = (config: MultiDimDataPageConfig) => {
@@ -135,7 +139,8 @@ const useView = (

const useVarDatapageData = (
config: MultiDimDataPageConfig,
currentView: ViewEnriched | undefined
currentView: ViewEnriched | undefined,
isPreviewing: boolean
) => {
const [varDatapageData, setVarDatapageData] =
useState<DataPageDataV2 | null>(null)
@@ -163,7 +168,7 @@ const useVarDatapageData = (
)
const grapherConfigUuid = currentView?.fullConfigId
const grapherConfigPromise = grapherConfigUuid
? cachedGetGrapherConfigByUuid(grapherConfigUuid)
? cachedGetGrapherConfigByUuid(grapherConfigUuid, isPreviewing)
: null

Promise.allSettled([datapageDataPromise, grapherConfigPromise])
@@ -189,6 +194,7 @@ const useVarDatapageData = (
currentView?.indicators,
currentView?.config,
currentView?.metadata,
isPreviewing,
])

return {
@@ -216,7 +222,7 @@ export const MultiDimDataPageContent = ({
canonicalUrl,
// _datapageData,
configObj,
// isPreviewing = false,
isPreviewing,
faqEntries,
primaryTopic,
tagToSlugMap,
@@ -242,7 +248,7 @@ export const MultiDimDataPageContent = ({

const currentView = useView(currentSettings, config)
const { varDatapageData, varGrapherConfig, grapherConfigIsReady } =
useVarDatapageData(config, currentView)
useVarDatapageData(config, currentView, isPreviewing ?? false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could also just set a default in the parameter destructuring 🙂


// This is the ACTUAL grapher instance being used, because GrapherFigureView/GrapherWithFallback are doing weird things and are not actually using the grapher instance we pass into it
// and therefore we can not access the grapher state (e.g. tab, selection) from the grapher instance we pass into it