Skip to content

Commit

Permalink
refactor: use more cache (#1071)
Browse files Browse the repository at this point in the history
* use more cache
* remove obsolete add area form
* refactor: only prebuild pages for prod
  • Loading branch information
vnugent authored Jan 11, 2024
1 parent e8ffc0e commit cbac957
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 29 deletions.
6 changes: 5 additions & 1 deletion src/app/area/[[...slug]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ const EditDescriptionCTA: React.FC<{ uuid: string }> = ({ uuid }) => (
* List of area pages to prebuild
*/
export function generateStaticParams (): PageSlugType[] {
return [
const list = [
{ slug: ['bea6bf11-de53-5046-a5b4-b89217b7e9bc'] }, // Red Rock
{ slug: ['78da26bc-cd94-5ac8-8e1c-815f7f30a28b'] }, // Red River Gorge
{ slug: ['1db1e8ba-a40e-587c-88a4-64f5ea814b8e'] }, // USA
Expand All @@ -180,6 +180,10 @@ export function generateStaticParams (): PageSlugType[] {
{ slug: ['b1166235-3328-5537-b5ed-92f406ea8495'] }, // Lander
{ slug: ['9abad566-2113-587e-95a5-b3abcfaa28ac'] } // Ten Sleep
]
if (process.env.VERCEL_ENV !== 'production') {
return list.slice(0, 1)
}
return list
}

// Page metadata
Expand Down
3 changes: 1 addition & 2 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import { RecentContributionsMap } from './components/recent/RecentContributionsM
/**
* Cache duration in seconds
*/
export const revalidate = 300
export const fetchCache = 'force-no-store' // opt out of Nextjs version of 'fetch'
export const revalidate = 3600

/**
* Root home page
Expand Down
21 changes: 0 additions & 21 deletions src/components/edit/DefaultView.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions src/js/graphql/contribAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ export const getChangeHistoryServerSide = async (): Promise<ChangesetType[]> =>
try {
const rs = await graphqlClient.query<{ getChangeHistory: ChangesetType[] }>({
query: QUERY_RECENT_CHANGE_HISTORY,
fetchPolicy: 'no-cache'
fetchPolicy: 'cache-first'
})

if (Array.isArray(rs.data?.getChangeHistory)) {
return rs.data?.getChangeHistory.splice(0, 50)
return rs.data?.getChangeHistory.slice(0, 50)
}
console.log('WARNING: getChangeHistory() returns non-array data')
return []
Expand Down
1 change: 1 addition & 0 deletions src/js/graphql/gql/contribs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ export const FRAGMENT_CHANGE_HISTORY = gql`
length
}
... on Organization {
orgId
displayName
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/pages/edit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import SeoTags from '../../components/SeoTags'
import Layout from '../../components/layout'
import { getChangeHistoryServerSide } from '../../js/graphql/contribAPI'
import { RecentChangeHistoryProps } from '../../components/edit/RecentChangeHistory'
import DefaultView from '../../components/edit/DefaultView'

interface PageProps {
history: any[]
}
Expand All @@ -22,7 +22,6 @@ const Page: NextPage<PageProps> = ({ history }: PageProps) => {
showFooter
>
<section className='max-w-lg mx-auto w-full'>
<DefaultView />
<h2 className='px-4 sm:px-0'>Recent history</h2>
<RecentChangeHistory history={history} />
</section>
Expand All @@ -38,7 +37,7 @@ export const getStaticProps: GetStaticProps<PageProps> = async ({ params }): Pro
props: {
history
},
revalidate: 5 // regenerate page when a request comes in but no faster than every 5s
revalidate: 30 // regenerate page when a request comes in but no faster than every 5s

This comment has been minimized.

Copy link
@musoke

musoke Jan 12, 2024

Contributor

should the comment be updated so number of seconds matches?

This comment has been minimized.

Copy link
@vnugent

vnugent Jan 12, 2024

Author Contributor

Yes, good catch. #1073

})
}

Expand Down

1 comment on commit cbac957

@vercel
Copy link

@vercel vercel bot commented on cbac957 Jan 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.