From 6a01efce18b28497ab8bd07162f74121cc8cc3ef Mon Sep 17 00:00:00 2001 From: Strtus Date: Tue, 19 May 2026 00:58:05 +0800 Subject: [PATCH] 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 --- src/app/static.ts | 6 +++++- src/db/index.ts | 9 ++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/app/static.ts b/src/app/static.ts index be50d1a1..8dbd4d1a 100644 --- a/src/app/static.ts +++ b/src/app/static.ts @@ -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 = ( getData: () => Promise, formatData: (data: T[]) => K[], ): (() => Promise) | undefined => + !STATIC_GENERATION_DISABLED && CATEGORY_VISIBILITY.includes(key) && ( (type === 'page' && STATICALLY_OPTIMIZED_PHOTO_CATEGORIES) || (type === 'image' && STATICALLY_OPTIMIZED_PHOTO_CATEGORY_OG_IMAGES) diff --git a/src/db/index.ts b/src/db/index.ts index c13c8d6a..9ab273aa 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -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