From cd731ab56bb3a00fc7c094405ed61cf867beb7ef Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Mon, 29 Apr 2024 23:08:58 -0500 Subject: [PATCH] Make static pages resilient to db-less installation --- src/admin/AdminNav.tsx | 2 +- src/app/admin/photos/page.tsx | 8 +++++--- src/app/admin/tags/page.tsx | 2 +- src/app/grid/page.tsx | 7 +++++-- src/app/home-image/route.tsx | 2 +- src/app/page.tsx | 2 -- src/app/template-image-tight/route.tsx | 2 +- src/app/template-image/route.tsx | 5 ++++- src/photo/data.ts | 10 ++++++---- 9 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/admin/AdminNav.tsx b/src/admin/AdminNav.tsx index 2185390f..0a4b26f2 100644 --- a/src/admin/AdminNav.tsx +++ b/src/admin/AdminNav.tsx @@ -26,7 +26,7 @@ export default async function AdminNav() { return 0; }), getUniqueTagsCached().then(tags => tags.length).catch(() => 0), - getPhotosMostRecentUpdateCached(), + getPhotosMostRecentUpdateCached().catch(() => undefined), ]); const navItemPhotos = { diff --git a/src/app/admin/photos/page.tsx b/src/app/admin/photos/page.tsx index f25f965c..41de1c79 100644 --- a/src/app/admin/photos/page.tsx +++ b/src/app/admin/photos/page.tsx @@ -26,9 +26,11 @@ export default async function AdminPhotosPage() { includeHidden: true, sortBy: 'createdAt', limit: INFINITE_SCROLL_INITIAL_ADMIN_PHOTOS, - }), - getPhotosCountIncludingHiddenCached(), - DEBUG_PHOTO_BLOBS ? getStoragePhotoUrlsNoStore() : [], + }).catch(() => []), + getPhotosCountIncludingHiddenCached().catch(() => 0), + DEBUG_PHOTO_BLOBS + ? getStoragePhotoUrlsNoStore() + : [], ]); return ( diff --git a/src/app/admin/tags/page.tsx b/src/app/admin/tags/page.tsx index c5eaba56..c70d03e7 100644 --- a/src/app/admin/tags/page.tsx +++ b/src/app/admin/tags/page.tsx @@ -3,7 +3,7 @@ import SiteGrid from '@/components/SiteGrid'; import { getUniqueTagsHiddenCached } from '@/photo/cache'; export default async function AdminTagsPage() { - const tags = await getUniqueTagsHiddenCached(); + const tags = await getUniqueTagsHiddenCached().catch(() => []); return ( { - const photos = await getPhotosCached({ limit: MAX_PHOTOS_TO_SHOW_OG }); + const photos = await getPhotosCached({ + limit: MAX_PHOTOS_TO_SHOW_OG, + }) + .catch(() => []); return generateOgImageMetaForPhotos(photos); } @@ -31,7 +34,7 @@ export default async function GridPage() { cameras, simulations, ] = await Promise.all([ - getPhotosCached({ limit: INFINITE_SCROLL_INITIAL_GRID }), + getPhotosCached({ limit: INFINITE_SCROLL_INITIAL_GRID }).catch(() => []), ...getPhotoSidebarData(), ]); diff --git a/src/app/home-image/route.tsx b/src/app/home-image/route.tsx index e60f58e6..7cb7acf7 100644 --- a/src/app/home-image/route.tsx +++ b/src/app/home-image/route.tsx @@ -17,7 +17,7 @@ export async function GET() { headers, { fontFamily, fonts }, ] = await Promise.all([ - getPhotosCached({ limit: MAX_PHOTOS_TO_SHOW_OG }), + getPhotosCached({ limit: MAX_PHOTOS_TO_SHOW_OG }).catch(() => []), getImageResponseCacheControlHeaders(), getIBMPlexMonoMedium(), ]); diff --git a/src/app/page.tsx b/src/app/page.tsx index de27623f..2104f14d 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -16,7 +16,6 @@ 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 getPhotosCached({ limit: MAX_PHOTOS_TO_SHOW_OG, }) @@ -25,7 +24,6 @@ export async function generateMetadata(): Promise { } export default async function HomePage() { - // Make homepage queries resilient to error on first time setup const [ photos, photosCount, diff --git a/src/app/template-image-tight/route.tsx b/src/app/template-image-tight/route.tsx index 5d444fc9..2f3816f1 100644 --- a/src/app/template-image-tight/route.tsx +++ b/src/app/template-image-tight/route.tsx @@ -19,7 +19,7 @@ export async function GET() { getPhotosCached({ sortBy: 'priority', limit: MAX_PHOTOS_TO_SHOW_TEMPLATE_TIGHT, - }), + }).catch(() => []), getIBMPlexMonoMedium(), getImageResponseCacheControlHeaders(), ]); diff --git a/src/app/template-image/route.tsx b/src/app/template-image/route.tsx index 8f8f9d9a..1b2c280b 100644 --- a/src/app/template-image/route.tsx +++ b/src/app/template-image/route.tsx @@ -16,7 +16,10 @@ export async function GET() { { fontFamily, fonts }, headers, ] = await Promise.all([ - getPhotosCached({ sortBy: 'priority', limit: MAX_PHOTOS_TO_SHOW_TEMPLATE }), + getPhotosCached({ + sortBy: 'priority', + limit: MAX_PHOTOS_TO_SHOW_TEMPLATE, + }).catch(() => []), getIBMPlexMonoMedium(), getImageResponseCacheControlHeaders(), ]); diff --git a/src/photo/data.ts b/src/photo/data.ts index caa294ee..e99b4a61 100644 --- a/src/photo/data.ts +++ b/src/photo/data.ts @@ -14,10 +14,12 @@ import { SHOW_FILM_SIMULATIONS } from '@/site/config'; import { sortTagsObject } from '@/tag'; export const getPhotoSidebarData = () => [ - getPhotosCount(), - getUniqueTags().then(sortTagsObject), - getUniqueCameras(), - SHOW_FILM_SIMULATIONS ? getUniqueFilmSimulations() : [], + getPhotosCount().catch(() => 0), + getUniqueTags().then(sortTagsObject).catch(() => []), + getUniqueCameras().catch(() => []), + SHOW_FILM_SIMULATIONS + ? getUniqueFilmSimulations().catch(() => []) + : [], ] as const; export const getPhotoSidebarDataCached = () => [