Refactor detail page for photos excluded from feeds

This commit is contained in:
Sam Becker 2025-07-07 21:35:27 -05:00
parent 6e76207708
commit 8eeda8d84e
3 changed files with 26 additions and 24 deletions

View File

@ -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',

View File

@ -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,
};
});

View File

@ -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}`);