From 1f0f9aa906ed52928e57775b1f7c893b697abbf5 Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Sun, 28 Apr 2024 11:09:33 -0500 Subject: [PATCH] Stop caching db requests on static home page --- src/app/page.tsx | 11 +++++++---- src/site/config.ts | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/app/page.tsx b/src/app/page.tsx index 427fb627..59ea960c 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,4 +1,3 @@ -import { getPhotosCachedCached, getPhotosCountCached } from '@/photo/cache'; import { INFINITE_SCROLL_INITIAL_HOME, INFINITE_SCROLL_MULTIPLE_HOME, @@ -9,12 +8,16 @@ import { Metadata } from 'next/types'; import { MAX_PHOTOS_TO_SHOW_OG } from '@/image-response'; import InfinitePhotoScroll from '../photo/InfinitePhotoScroll'; import PhotosLarge from '@/photo/PhotosLarge'; +import { cache } from 'react'; +import { getPhotos, getPhotosCount } from '@/services/vercel-postgres'; export const dynamic = 'force-static'; +const getPhotosCached = cache(getPhotos); + export async function generateMetadata(): Promise { // Make homepage queries resilient to error on first time setup - const photos = await getPhotosCachedCached({ + const photos = await getPhotosCached({ limit: MAX_PHOTOS_TO_SHOW_OG, }) .catch(() => []); @@ -27,11 +30,11 @@ export default async function HomePage() { photos, photosCount, ] = await Promise.all([ - getPhotosCachedCached({ + getPhotosCached({ limit: INFINITE_SCROLL_INITIAL_HOME, }) .catch(() => []), - getPhotosCountCached() + getPhotosCount() .catch(() => 0), ]); diff --git a/src/site/config.ts b/src/site/config.ts index 0c10a34c..0c5d0b2d 100644 --- a/src/site/config.ts +++ b/src/site/config.ts @@ -5,7 +5,7 @@ import { makeUrlAbsolute, shortenUrl } from '@/utility/url'; // HARD-CODED GLOBAL CONFIGURATION export const SHOULD_PREFETCH_ALL_LINKS: boolean | undefined = undefined; -export const SHOULD_DEBUG_SQL = false; +export const SHOULD_DEBUG_SQL = true; // META / DOMAINS