From 0f4d708f6af0f0c8b2329645dfb504cd762a3d96 Mon Sep 17 00:00:00 2001 From: Mike Decker Date: Tue, 23 Jan 2024 12:44:16 -0800 Subject: [PATCH] Add cache busting string --- app/api/revalidate/route.tsx | 2 +- src/lib/drupal/get-paths.tsx | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/api/revalidate/route.tsx b/app/api/revalidate/route.tsx index a33d5c09..0ef8e436 100644 --- a/app/api/revalidate/route.tsx +++ b/app/api/revalidate/route.tsx @@ -23,7 +23,7 @@ export const GET = async (request: NextRequest) => { } tagsInvalidated.map(tag => revalidateTag(tag)); - await getAllDrupalPaths(); + await getAllDrupalPaths(true); revalidatePath(path); return NextResponse.json({revalidated: true, path, tags: tagsInvalidated}); } \ No newline at end of file diff --git a/src/lib/drupal/get-paths.tsx b/src/lib/drupal/get-paths.tsx index 00d4e505..62482c3a 100644 --- a/src/lib/drupal/get-paths.tsx +++ b/src/lib/drupal/get-paths.tsx @@ -17,20 +17,22 @@ export const pathIsValid = async (path: string, type?: 'node' | 'redirect') => { return allPaths.includes(path); } -export const getAllDrupalPaths = async (): Promise> => { +export const getAllDrupalPaths = async (cacheBust?: boolean): Promise> => { const paths = new Map(); - paths.set('node', await getNodePaths()) - paths.set('redirect', await getRedirectPaths()) + paths.set('node', await getNodePaths(cacheBust)) + paths.set('redirect', await getRedirectPaths(cacheBust)) return paths; } -const getNodePaths = async (): Promise => { +const getNodePaths = async (cacheBust?: boolean): Promise => { const params = new DrupalJsonApiParams(); // Add a simple include so that it doesn't fetch all the data right now. The full node data comes later, we only need // the node paths. params.addInclude(['node_type']); params.addPageLimit(50); + if (cacheBust) params.addCustomParam({'cache': new Date().getTime()}) + const contentTypes = [ 'node--stanford_page', 'node--stanford_event', @@ -61,7 +63,7 @@ const getNodePaths = async (): Promise => { return paths.map(pagePath => getPathFromContext(pagePath)).filter(path => !!path); } -const getRedirectPaths = async (): Promise => { +const getRedirectPaths = async (cacheBust?: boolean): Promise => { const params = new DrupalJsonApiParams(); params.addPageLimit(50);