perf: optimize public content caching
This commit is contained in:
@@ -3,6 +3,7 @@ import Link from 'next/link'
|
||||
import { setRequestLocale } from 'next-intl/server'
|
||||
import type { Locale } from '@/i18n/config'
|
||||
import { PageHero } from '@/components/site/page-hero'
|
||||
import { cacheCmsQuery } from '@/lib/cms-cache'
|
||||
import { getPayloadClient } from '@/lib/payload'
|
||||
import { buildAbsoluteUrl, buildLocaleAlternates } from '@/lib/seo'
|
||||
import { normalizeUploadUrl } from '@/lib/upload-url'
|
||||
@@ -292,7 +293,7 @@ function getMapPoints(dealers: Dealer[]) {
|
||||
return [...grouped.values()].sort((left, right) => left.region.localeCompare(right.region))
|
||||
}
|
||||
|
||||
async function getDealersPageSettings(locale: Locale) {
|
||||
async function getDealersPageSettingsUncached(locale: Locale) {
|
||||
const payload = await getPayloadClient()
|
||||
|
||||
try {
|
||||
@@ -348,7 +349,12 @@ async function getDealersPageSettings(locale: Locale) {
|
||||
}
|
||||
}
|
||||
|
||||
async function getDealersPageData(locale: Locale) {
|
||||
const getDealersPageSettings = cacheCmsQuery<
|
||||
[Locale],
|
||||
Awaited<ReturnType<typeof getDealersPageSettingsUncached>>
|
||||
>(['dealers-page-global'], getDealersPageSettingsUncached)
|
||||
|
||||
async function getDealersPageDataUncached(locale: Locale) {
|
||||
const payload = await getPayloadClient()
|
||||
const result = await payload.find({
|
||||
collection: 'dealers',
|
||||
@@ -381,6 +387,11 @@ async function getDealersPageData(locale: Locale) {
|
||||
}
|
||||
}
|
||||
|
||||
const getDealersPageData = cacheCmsQuery<[Locale], Awaited<ReturnType<typeof getDealersPageDataUncached>>>(
|
||||
['dealers-page-data'],
|
||||
getDealersPageDataUncached,
|
||||
)
|
||||
|
||||
function DealerTabs({
|
||||
activeTab,
|
||||
locale,
|
||||
@@ -677,8 +688,10 @@ export default async function WhereToBuyPage({
|
||||
const query = await searchParams
|
||||
setRequestLocale(locale)
|
||||
|
||||
const { dealerDocs, dealerGroups, storeDocs } = await getDealersPageData(locale)
|
||||
const settings = await getDealersPageSettings(locale)
|
||||
const [{ dealerDocs, dealerGroups, storeDocs }, settings] = await Promise.all([
|
||||
getDealersPageData(locale),
|
||||
getDealersPageSettings(locale),
|
||||
])
|
||||
const hasDealers = dealerDocs.length > 0
|
||||
const hasStores = storeDocs.length > 0
|
||||
const shouldShowTabs = hasDealers && hasStores
|
||||
|
||||
Reference in New Issue
Block a user