Skip to content

Commit

Permalink
Adjust caches
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish committed Aug 3, 2024
1 parent 73d637f commit 13c0821
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
16 changes: 16 additions & 0 deletions app/api/revalidate/page/route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {NextRequest, NextResponse} from "next/server"
import {revalidatePath} from "next/cache"

export const revalidate = 0

export const GET = async (request: NextRequest) => {
const secret = request.nextUrl.searchParams.get("secret")
if (secret !== process.env.DRUPAL_REVALIDATE_SECRET)
return NextResponse.json({message: "Invalid token"}, {status: 403})

let path = request.nextUrl.searchParams.get("slug")
if (!path || path.startsWith("/node/")) return NextResponse.json({message: "Invalid slug"}, {status: 400})
revalidatePath(path)

return NextResponse.json({revalidated: true, path})
}
4 changes: 2 additions & 2 deletions app/api/revalidate/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ export const GET = async (request: NextRequest) => {
.split("/")
.map(tag => tagsInvalidated.push(tag))

tagsInvalidated.map(tag => revalidateTag(tag))

const menu = await getMenu()
if (!!getMenuActiveTrail(menu, path).length) tagsInvalidated.push("menu:main")

tagsInvalidated.map(tag => revalidateTag(tag))

return NextResponse.json({revalidated: true, tags: tagsInvalidated})
}
6 changes: 3 additions & 3 deletions src/lib/gql/gql-queries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const getConfigPage = async <T extends ConfigPagesUnion>(
async () => {
let query: ConfigPagesQuery
try {
query = await graphqlClient({next: {tags: ["config-pages"]}}).ConfigPages()
query = await graphqlClient({cache: "no-cache"}).ConfigPages()
} catch (e) {
console.warn("Unable to fetch config pages: " + (e instanceof Error && e.stack))
return
Expand Down Expand Up @@ -104,7 +104,7 @@ export const getMenu = cache(async (name?: MenuAvailable, maxLevels?: number): P

const getData = nextCache(
async () => {
const menu = await graphqlClient({next: {tags: [`menu:${menuName}`]}}).Menu({name})
const menu = await graphqlClient({cache: "no-cache"}).Menu({name})
const menuItems = (menu.menu?.items || []) as MenuItem[]

const filterInaccessible = (items: MenuItem[], level: number): MenuItem[] => {
Expand Down Expand Up @@ -133,7 +133,7 @@ export const getAllNodes = nextCache(
const cursors: Omit<AllNodesQueryVariables, "first"> = {}

while (fetchMore) {
nodeQuery = await graphqlClient({next: {tags: ["paths"]}}).AllNodes({first: 1000, ...cursors})
nodeQuery = await graphqlClient({cache: "no-cache"}).AllNodes({first: 1000, ...cursors})
queryKeys = Object.keys(nodeQuery) as (keyof AllNodesQuery)[]
fetchMore = false

Expand Down

0 comments on commit 13c0821

Please sign in to comment.