From 573d8591995a70cb7a0f296fb502affd6f589eba Mon Sep 17 00:00:00 2001 From: Mike Decker Date: Fri, 13 Dec 2024 08:10:35 -0800 Subject: [PATCH] Small cache change --- src/lib/gql/gql-queries.tsx | 8 ++--- src/lib/utils/getLegacyBookPaths.tsx | 49 +++++++++++++++------------- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/src/lib/gql/gql-queries.tsx b/src/lib/gql/gql-queries.tsx index 96062b7..16018fb 100644 --- a/src/lib/gql/gql-queries.tsx +++ b/src/lib/gql/gql-queries.tsx @@ -63,7 +63,7 @@ export const getEntityFromPath = async ( } export const getConfigPage = nextCache( - cache(async (configPageType: ConfigPagesUnion["__typename"]): Promise => { + async (configPageType: ConfigPagesUnion["__typename"]): Promise => { let query: ConfigPagesQuery try { query = await graphqlClient({next: {tags: ["config-pages"]}}).ConfigPages() @@ -79,16 +79,16 @@ export const getConfigPage = nextCache( return query[queryKey].nodes[0] as T } } - }), + }, [], {tags: ["config-pages"]} ) export const getConfigPageField = nextCache( - cache(async (configPageType: ConfigPagesUnion["__typename"], fieldName: keyof T) => { + async (configPageType: ConfigPagesUnion["__typename"], fieldName: keyof T) => { const configPage = await getConfigPage(configPageType) return configPage?.[fieldName] as F - }), + }, [], {tags: ["config-pages"]} ) diff --git a/src/lib/utils/getLegacyBookPaths.tsx b/src/lib/utils/getLegacyBookPaths.tsx index b8f394e..f7d5ba7 100644 --- a/src/lib/utils/getLegacyBookPaths.tsx +++ b/src/lib/utils/getLegacyBookPaths.tsx @@ -1,30 +1,33 @@ import {BooksWorkIdQuery, BooksWorkIdQueryVariables} from "@lib/gql/__generated__/drupal.d" import {graphqlClient} from "@lib/gql/gql-client" import {unstable_cache as nextCache} from "next/cache" +import {cache} from "react" -export const getLegacyBookPaths = nextCache( - async () => { - const nodes: Array<{id: number; path: string}> = [] - let fetchMore = true - let nodeQuery: BooksWorkIdQuery - const cursors: Omit = {} +export const getLegacyBookPaths = cache( + nextCache( + async () => { + const nodes: Array<{id: number; path: string}> = [] + let fetchMore = true + let nodeQuery: BooksWorkIdQuery + const cursors: Omit = {} - while (fetchMore) { - nodeQuery = await graphqlClient({cache: "no-cache"}).BooksWorkId({first: 1000, ...cursors}) - nodeQuery.nodeSupBooks.nodes - .filter(node => !!node.supBookWorkIdNumber) - .map(node => - nodes.push({ - id: node.supBookWorkIdNumber as number, - path: node.path, - }) - ) - cursors.after = nodeQuery.nodeSupBooks.pageInfo.endCursor - fetchMore = nodeQuery.nodeSupBooks.pageInfo.hasNextPage - } + while (fetchMore) { + nodeQuery = await graphqlClient({cache: "no-cache"}).BooksWorkId({first: 1000, ...cursors}) + nodeQuery.nodeSupBooks.nodes + .filter(node => !!node.supBookWorkIdNumber) + .map(node => + nodes.push({ + id: node.supBookWorkIdNumber as number, + path: node.path, + }) + ) + cursors.after = nodeQuery.nodeSupBooks.pageInfo.endCursor + fetchMore = nodeQuery.nodeSupBooks.pageInfo.hasNextPage + } - return nodes - }, - [], - {tags: ["legacy-books"]} + return nodes + }, + [], + {tags: ["legacy-books"]} + ) )