Skip to content

Commit

Permalink
Add cache busting string
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish committed Jan 23, 2024
1 parent 1fd3e1f commit 0f4d708
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/api/revalidate/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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});
}
12 changes: 7 additions & 5 deletions src/lib/drupal/get-paths.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,22 @@ export const pathIsValid = async (path: string, type?: 'node' | 'redirect') => {
return allPaths.includes(path);
}

export const getAllDrupalPaths = async (): Promise<Map<string, string[]>> => {
export const getAllDrupalPaths = async (cacheBust?: boolean): Promise<Map<string, string[]>> => {
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<string[]> => {
const getNodePaths = async (cacheBust?: boolean): Promise<string[]> => {
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',
Expand Down Expand Up @@ -61,7 +63,7 @@ const getNodePaths = async (): Promise<string[]> => {
return paths.map(pagePath => getPathFromContext(pagePath)).filter(path => !!path);
}

const getRedirectPaths = async (): Promise<string[]> => {
const getRedirectPaths = async (cacheBust?: boolean): Promise<string[]> => {
const params = new DrupalJsonApiParams();
params.addPageLimit(50);

Expand Down

0 comments on commit 0f4d708

Please sign in to comment.