diff --git a/app/p/[photoId]/page.tsx b/app/p/[photoId]/page.tsx index 33a7a29a..57a7310b 100644 --- a/app/p/[photoId]/page.tsx +++ b/app/p/[photoId]/page.tsx @@ -11,20 +11,29 @@ import { absolutePathForPhotoImage, } from '@/app/paths'; import PhotoDetailPage from '@/photo/PhotoDetailPage'; -import { getPhotosNearIdCached } from '@/photo/cache'; +import { getPhotoCached, getPhotosNearIdCached } from '@/photo/cache'; import { cache } from 'react'; import { staticallyGeneratePhotosIfConfigured } from '@/app/static'; export const maxDuration = 60; -const getPhotosNearIdCachedCached = cache((photoId: string) => - getPhotosNearIdCached( - photoId, { - limit: RELATED_GRID_PHOTOS_TO_SHOW + 2, - }, - // Don't show photo in context when excluded from feeds - true, - )); +const getPhotosNearIdCachedCached = cache(async (photoId: string) => { + const photo = await getPhotoCached(photoId); + // Omit related photos when photo is excluded from feeds + return photo?.excludeFromFeeds + ? { + photo: photo, + photos: [], + photosGrid: [], + indexNumber: 0, + } + :getPhotosNearIdCached( + photoId, { + limit: RELATED_GRID_PHOTOS_TO_SHOW + 2, + excludeFromFeeds: true, + }, + ); +}); export const generateStaticParams = staticallyGeneratePhotosIfConfigured( 'page', diff --git a/src/photo/cache.ts b/src/photo/cache.ts index 5fb08ee9..84f26a66 100644 --- a/src/photo/cache.ts +++ b/src/photo/cache.ts @@ -179,23 +179,18 @@ export const getPhotosNearIdCached = ( getPhotosNearId, [KEY_PHOTOS, ...getPhotosCacheKeys(args[1])], )(...args).then(({ photos, indexNumber }) => { - const [photoId, { limit }, excludeFromFeeds] = args; + const [photoId, { limit }] = args; const photo = photos.find(({ id }) => id === photoId); const isPhotoFirst = photos.findIndex(p => p.id === photoId) === 0; return { photo: photo ? parseCachedPhotoDates(photo) : undefined, - // Don't show photo in context when excluded from feeds - ...excludeFromFeeds && photo?.excludeFromFeeds - ? { photos: [] } - : { - photos: parseCachedPhotosDates(photos), - ...limit && { - photosGrid: photos.slice( - isPhotoFirst ? 1 : 2, - isPhotoFirst ? limit - 1 : limit, - ), - }, - }, + photos: parseCachedPhotosDates(photos), + ...limit && { + photosGrid: photos.slice( + isPhotoFirst ? 1 : 2, + isPhotoFirst ? limit - 1 : limit, + ), + }, indexNumber, }; }); diff --git a/src/photo/db/query.ts b/src/photo/db/query.ts index 2442a7f3..ec8beffa 100644 --- a/src/photo/db/query.ts +++ b/src/photo/db/query.ts @@ -531,7 +531,6 @@ export const getPhotos = async (options: PhotoQueryOptions = {}) => export const getPhotosNearId = async ( photoId: string, options: PhotoQueryOptions, - excludeFromFeeds?: boolean, ) => safelyQueryPhotos(async () => { const { limit } = options; @@ -566,7 +565,6 @@ export const getPhotosNearId = async ( return { photos: rows.map(parsePhotoFromDb), indexNumber, - excludeFromFeeds, }; }); }, `getPhotosNearId: ${photoId}`);