Add static generation throttles for constrained build environments
Allow disabling static generation and tuning static params limits via env vars to reduce build output size on low-disk CI providers. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
053a3b4acc
commit
6a01efce18
@ -12,6 +12,8 @@ import { getAllPublicPhotoIds } from '@/photo/query';
|
||||
import { depluralize, pluralize } from '@/utility/string';
|
||||
|
||||
type StaticOutput = 'page' | 'image';
|
||||
const STATIC_GENERATION_DISABLED =
|
||||
process.env.DISABLE_STATIC_GENERATION === '1';
|
||||
|
||||
const logStaticGenerationDetails = (count: number, content: string) => {
|
||||
if (count > 0) {
|
||||
@ -21,9 +23,10 @@ const logStaticGenerationDetails = (count: number, content: string) => {
|
||||
};
|
||||
|
||||
export const staticallyGeneratePhotosIfConfigured = (type: StaticOutput) => (
|
||||
!STATIC_GENERATION_DISABLED && (
|
||||
(type === 'page' && STATICALLY_OPTIMIZED_PHOTOS) ||
|
||||
(type === 'image' && STATICALLY_OPTIMIZED_PHOTO_OG_IMAGES)
|
||||
)
|
||||
))
|
||||
? async () => {
|
||||
const photoIds = await getAllPublicPhotoIds({
|
||||
limit: GENERATE_STATIC_PARAMS_LIMIT,
|
||||
@ -45,6 +48,7 @@ export const staticallyGenerateCategoryIfConfigured = <T, K>(
|
||||
getData: () => Promise<T[]>,
|
||||
formatData: (data: T[]) => K[],
|
||||
): (() => Promise<K[]>) | undefined =>
|
||||
!STATIC_GENERATION_DISABLED &&
|
||||
CATEGORY_VISIBILITY.includes(key) && (
|
||||
(type === 'page' && STATICALLY_OPTIMIZED_PHOTO_CATEGORIES) ||
|
||||
(type === 'image' && STATICALLY_OPTIMIZED_PHOTO_CATEGORY_OG_IMAGES)
|
||||
|
||||
@ -9,7 +9,14 @@ import { getAlbumFromSlug } from '@/album/query';
|
||||
import { isTagPrivate } from '@/tag';
|
||||
import { getPhotoCount } from '@/photo/query';
|
||||
|
||||
export const GENERATE_STATIC_PARAMS_LIMIT = 1000;
|
||||
const staticParamsLimitRaw = parseInt(
|
||||
process.env.GENERATE_STATIC_PARAMS_LIMIT || '1000',
|
||||
10,
|
||||
);
|
||||
export const GENERATE_STATIC_PARAMS_LIMIT =
|
||||
Number.isFinite(staticParamsLimitRaw) && staticParamsLimitRaw > 0
|
||||
? staticParamsLimitRaw
|
||||
: 1000;
|
||||
export const PHOTO_DEFAULT_LIMIT = 100;
|
||||
|
||||
// These must mirror utility/string.ts parameterization
|
||||
|
||||
Loading…
Reference in New Issue
Block a user