Skip to content

Commit

Permalink
Adjust cache mechanisms to have more control with unstable_cache func…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
pookmish committed Jul 24, 2024
1 parent f66c067 commit 28a0e74
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 108 deletions.
23 changes: 7 additions & 16 deletions app/search/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {H1} from "@components/elements/headers"
import {getConfigPage} from "@lib/gql/gql-queries"
import {StanfordBasicSiteSetting} from "@lib/gql/__generated__/drupal.d"
import {getAlgoliaCredential} from "@lib/gql/gql-queries"
import {IndexUiState} from "instantsearch.js/es/types/ui-state"
import AlgoliaSearch from "@components/algolia/algolia-search"

Expand All @@ -17,7 +16,7 @@ export const metadata = {
},
}
const Page = async ({searchParams}: {searchParams?: {[_key: string]: string}}) => {
const siteSettingsConfig = await getConfigPage<StanfordBasicSiteSetting>("StanfordBasicSiteSetting")
const [appId, indexName, apiKey] = await getAlgoliaCredential()

const initialState: IndexUiState = {refinementList: {}}
if (searchParams?.q) initialState.query = searchParams.q as string
Expand All @@ -29,19 +28,11 @@ const Page = async ({searchParams}: {searchParams?: {[_key: string]: string}}) =
Search
</H1>

{siteSettingsConfig?.suSiteAlgoliaId &&
siteSettingsConfig?.suSiteAlgoliaIndex &&
siteSettingsConfig?.suSiteAlgoliaSearch && (
<>
<AlgoliaSearch
appId={siteSettingsConfig.suSiteAlgoliaId}
searchIndex={siteSettingsConfig.suSiteAlgoliaIndex}
searchApiKey={siteSettingsConfig.suSiteAlgoliaSearch}
initialUiState={initialState}
/>
<noscript>Please enable javascript to view search results</noscript>
</>
)}
{appId && (
<AlgoliaSearch appId={appId} searchIndex={indexName} searchApiKey={apiKey} initialUiState={initialState} />
)}
{!appId && <p>Search is currently unavailable.</p>}
<noscript>Please enable javascript to view search results</noscript>
</div>
</div>
)
Expand Down
1 change: 1 addition & 0 deletions public/robots.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
User-agent: *
Allow: /
Disallow: /api/
Disallow: /search
crawl-delay: 30
20 changes: 19 additions & 1 deletion src/lib/gql/__generated__/drupal.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 18 additions & 9 deletions src/lib/gql/__generated__/queries.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 16 additions & 8 deletions src/lib/gql/entity-queries.drupal.gql
Original file line number Diff line number Diff line change
Expand Up @@ -10,66 +10,74 @@ fragment FragmentPageInfo on ConnectionPageInfo {
endCursor
}

fragment AllNodeInterface on NodeInterface {
id
path
changed {
time
}
}

query AllNodes($first: Int = 1000, $nodeStanfordCourses: Cursor, $nodeStanfordEventSeriesItems: Cursor, $nodeStanfordEvents: Cursor, $nodeStanfordNewsItems: Cursor, $nodeStanfordPages: Cursor, $nodeStanfordPeople: Cursor, $nodeStanfordPolicies: Cursor, $nodeStanfordPublications: Cursor) {
nodeStanfordCourses(first: $first, after: $nodeStanfordCourses, sortKey: CREATED_AT) {
nodes {
...FragmentNodeInterface
...AllNodeInterface
}
pageInfo {
...FragmentPageInfo
}
}
nodeStanfordEventSeriesItems(first: $first, after: $nodeStanfordEventSeriesItems, sortKey: CREATED_AT) {
nodes {
...FragmentNodeInterface
...AllNodeInterface
}
pageInfo {
...FragmentPageInfo
}
}
nodeStanfordEvents(first: $first, after: $nodeStanfordEvents, sortKey: CREATED_AT) {
nodes {
...FragmentNodeInterface
...AllNodeInterface
}
pageInfo {
...FragmentPageInfo
}
}
nodeStanfordNewsItems(first: $first, after: $nodeStanfordNewsItems, sortKey: CREATED_AT) {
nodes {
...FragmentNodeInterface
...AllNodeInterface
}
pageInfo {
...FragmentPageInfo
}
}
nodeStanfordPages(first: $first, after: $nodeStanfordPages, sortKey: CREATED_AT) {
nodes {
...FragmentNodeInterface
...AllNodeInterface
}
pageInfo {
...FragmentPageInfo
}
}
nodeStanfordPeople(first: $first, after: $nodeStanfordPeople, sortKey: CREATED_AT) {
nodes {
...FragmentNodeInterface
...AllNodeInterface
}
pageInfo {
...FragmentPageInfo
}
}
nodeStanfordPolicies(first: $first, after: $nodeStanfordPolicies, sortKey: CREATED_AT) {
nodes {
...FragmentNodeInterface
...AllNodeInterface
}
pageInfo {
...FragmentPageInfo
}
}
nodeStanfordPublications(first: $first, after: $nodeStanfordPublications, sortKey: CREATED_AT) {
nodes {
...FragmentNodeInterface
...AllNodeInterface
}
pageInfo {
...FragmentPageInfo
Expand Down
5 changes: 1 addition & 4 deletions src/lib/gql/gql-client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ export const graphqlClient = (requestConfig: Omit<RequestInit, "method"> = {}, i

const client = new GraphQLClient(process.env.NEXT_PUBLIC_DRUPAL_BASE_URL + "/graphql", {
...requestConfig,
next: {
revalidate: 60 * 60 * 24 * 365,
...requestConfig.next,
},
next: requestConfig.cache ? {...requestConfig.next} : {revalidate: 60 * 60 * 24 * 365, ...requestConfig.next},
// Use fetch function so Next.js will be able to cache it normally.
fetch: async (input: URL | RequestInfo, init?: RequestInit) => fetch(input, init),
})
Expand Down
Loading

0 comments on commit 28a0e74

Please sign in to comment.