Stop caching /grid db requests

This commit is contained in:
Sam Becker 2024-04-28 12:55:30 -05:00
parent 618f033741
commit 7ab54e4868
2 changed files with 21 additions and 7 deletions

View File

@ -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<Metadata> {
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 (

View File

@ -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;