fix: gallery.yaml album order on homepage + stale settings cache (#391)

* fix: honour gallery.yaml order for homepage albums

getStandaloneAlbums() filtered the Immich API album list but kept the
API's own (creation/update) order, so reordering the albums list in
gallery.yaml or the admin panel had no effect on the homepage. Sort by
the config list's index instead.

Fixes #352

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix: serve fresh settings after admin save without restart

getConfig() short-circuited on a per-worker in-memory cache in
production. Admin saves invalidate that cache only in the worker that
handles the API request; when Next.js renders pages in a different
worker/process, its copy stayed stale until a container restart.

Drop the in-memory config cache entirely and rebuild the config per
call. Freshness comes from the existing mtime-checked YAML cache in
loadYaml() — one statSync per file, negligible next to Immich API
calls, and the same behaviour dev mode has always had.

Fixes #351

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: ralksta <ralksta@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Ralksta
2026-08-05 00:27:06 +02:00
committed by GitHub
parent de3e2d327c
commit f03011e0ec
4 changed files with 93 additions and 17 deletions

View File

@@ -16,11 +16,8 @@ import {
export * from './schema';
export * from './theme';
let _config: AppConfig | null = null;
/** Invalidate the cached config so the next getConfig() call re-reads YAML files. */
/** Invalidate the cached YAML so the next getConfig() call re-parses the files. */
export function invalidateConfigCache(): void {
_config = null;
clearYamlCache();
}
@@ -49,12 +46,10 @@ export function buildSubpageGrid(raw?: {
}
export function getConfig(): AppConfig {
// _config is a per-worker in-memory cache.
// invalidateConfigCache() clears it + the underlying YAML mtime cache,
// so after an admin save every worker re-parses on next request.
// In dev we always re-parse so hot-reload works.
if (_config && process.env.NODE_ENV === 'production') return _config;
// No in-memory config cache: admin saves can land in a different
// worker/process than page rendering, so a per-worker cache goes stale
// until restart. Freshness comes from the mtime-checked YAML cache in
// loadYaml() — a statSync per file, negligible next to Immich API calls.
const apiUrl = env.IMMICH_API_URL;
const apiKey = env.IMMICH_API_KEY;
const authSecret = resolveAuthSecret();
@@ -64,7 +59,7 @@ export function getConfig(): AppConfig {
if (!gallery || !apiKey || !apiUrl) {
// Return dummy config if gallery.yaml is missing
_config = {
return {
immich: { apiUrl: `${apiUrl}/api`, apiKey },
authSecret,
albums: [],
@@ -96,7 +91,6 @@ export function getConfig(): AppConfig {
trustedProxyHops: env.TRUSTED_PROXY_HOPS,
needsSetup: true,
};
return _config;
}
const theme = resolveTheme(settings.theme);
@@ -215,7 +209,7 @@ export function getConfig(): AppConfig {
const subpageAlbumIds = new Set(subpages.flatMap((sp) => sp.albumIds));
const allAlbumIds = [...new Set([...standaloneAlbumIds, ...subpageAlbumIds])];
_config = {
return {
immich: { apiUrl: `${apiUrl}/api`, apiKey },
authSecret,
albums: allAlbumIds,
@@ -280,5 +274,4 @@ export function getConfig(): AppConfig {
trustedProxyHops: env.TRUSTED_PROXY_HOPS,
needsSetup: false,
};
return _config;
}