From 7ab54e48687075651a54499d977d1a37c4d42154 Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Sun, 28 Apr 2024 12:55:30 -0500 Subject: [PATCH] Stop caching /grid db requests --- src/app/grid/page.tsx | 9 ++++++--- src/photo/data.ts | 19 +++++++++++++++---- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/app/grid/page.tsx b/src/app/grid/page.tsx index 03d93c11..8a1ffb51 100644 --- a/src/app/grid/page.tsx +++ b/src/app/grid/page.tsx @@ -1,4 +1,3 @@ -import { getPhotosCached } from '@/photo/cache'; import SiteGrid from '@/components/SiteGrid'; import { INFINITE_SCROLL_INITIAL_GRID, @@ -10,11 +9,15 @@ import PhotosEmptyState from '@/photo/PhotosEmptyState'; import { MAX_PHOTOS_TO_SHOW_OG } from '@/image-response'; import { Metadata } from 'next/types'; import PhotoGridSidebar from '@/photo/PhotoGridSidebar'; -import { getPhotoSidebarDataCached } from '@/photo/data'; +import { getPhotoSidebarData } from '@/photo/data'; import InfinitePhotoScroll from '@/photo/InfinitePhotoScroll'; +import { getPhotos } from '@/services/vercel-postgres'; +import { cache } from 'react'; export const dynamic = 'force-static'; +const getPhotosCached = cache(getPhotos); + export async function generateMetadata(): Promise { const photos = await getPhotosCached({ limit: MAX_PHOTOS_TO_SHOW_OG }); return generateOgImageMetaForPhotos(photos); @@ -29,7 +32,7 @@ export default async function GridPage() { simulations, ] = await Promise.all([ getPhotosCached({ limit: INFINITE_SCROLL_INITIAL_GRID }), - ...getPhotoSidebarDataCached(), + ...getPhotoSidebarData(), ]); return ( diff --git a/src/photo/data.ts b/src/photo/data.ts index 9705f779..caa294ee 100644 --- a/src/photo/data.ts +++ b/src/photo/data.ts @@ -4,14 +4,25 @@ import { getUniqueFilmSimulationsCached, getUniqueTagsCached, } from '@/photo/cache'; +import { + getPhotosCount, + getUniqueCameras, + getUniqueFilmSimulations, + getUniqueTags, +} from '@/services/vercel-postgres'; import { SHOW_FILM_SIMULATIONS } from '@/site/config'; -import { TAG_FAVS } from '@/tag'; +import { sortTagsObject } from '@/tag'; + +export const getPhotoSidebarData = () => [ + getPhotosCount(), + getUniqueTags().then(sortTagsObject), + getUniqueCameras(), + SHOW_FILM_SIMULATIONS ? getUniqueFilmSimulations() : [], +] as const; export const getPhotoSidebarDataCached = () => [ getPhotosCountCached(), - getUniqueTagsCached().then(tags => - tags.filter(({ tag }) => tag === TAG_FAVS).concat( - tags.filter(({ tag }) => tag !== TAG_FAVS))), + getUniqueTagsCached().then(sortTagsObject), getUniqueCamerasCached(), SHOW_FILM_SIMULATIONS ? getUniqueFilmSimulationsCached() : [], ] as const;