fix: clear album cache on admin save so changes appear immediately

When saving gallery/settings via admin, the config cache was invalidated
but the Immich album cache (which stores resolved title overrides and
descriptions) was not cleared. This meant changes only appeared after
the TTL expired or a manual 'Reload' click.

Now both gallery and settings saves also call immich.invalidateAll()
to flush the album cache, making changes visible on next page load.
This commit is contained in:
ralksta
2026-05-29 17:47:08 +02:00
parent 3a8a890930
commit 2e4cde4b6e
3 changed files with 6 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ import { NextResponse } from 'next/server';
import { isAdminAuthenticated, isAdminEnabled } from '@/lib/admin/auth'; import { isAdminAuthenticated, isAdminEnabled } from '@/lib/admin/auth';
import { readGalleryYaml, writeGalleryYaml } from '@/lib/admin/yaml-service'; import { readGalleryYaml, writeGalleryYaml } from '@/lib/admin/yaml-service';
import { invalidateConfigCache } from '@/lib/config'; import { invalidateConfigCache } from '@/lib/config';
import { immich } from '@/lib/immich';
import type { GalleryYaml } from '@/lib/config/schema'; import type { GalleryYaml } from '@/lib/config/schema';
/** GET: Read current gallery.yaml config. */ /** GET: Read current gallery.yaml config. */
@@ -40,6 +41,7 @@ export async function PUT(request: Request) {
try { try {
await writeGalleryYaml(gallery); await writeGalleryYaml(gallery);
invalidateConfigCache(); invalidateConfigCache();
immich.invalidateAll();
return NextResponse.json({ success: true, message: 'Saved successfully. Backup of previous version created.' }); return NextResponse.json({ success: true, message: 'Saved successfully. Backup of previous version created.' });
} catch (err) { } catch (err) {
console.error('[Admin] Failed to write gallery.yaml:', err); console.error('[Admin] Failed to write gallery.yaml:', err);

View File

@@ -2,6 +2,7 @@ import { NextResponse } from 'next/server';
import { isAdminAuthenticated, isAdminEnabled } from '@/lib/admin/auth'; import { isAdminAuthenticated, isAdminEnabled } from '@/lib/admin/auth';
import { readSettingsYaml, writeSettingsYaml } from '@/lib/admin/yaml-service'; import { readSettingsYaml, writeSettingsYaml } from '@/lib/admin/yaml-service';
import { invalidateConfigCache } from '@/lib/config'; import { invalidateConfigCache } from '@/lib/config';
import { immich } from '@/lib/immich';
import type { SettingsYaml } from '@/lib/config/schema'; import type { SettingsYaml } from '@/lib/config/schema';
/** GET: Read current settings.yaml config. */ /** GET: Read current settings.yaml config. */
@@ -36,6 +37,7 @@ export async function PUT(request: Request) {
try { try {
await writeSettingsYaml(settings); await writeSettingsYaml(settings);
invalidateConfigCache(); invalidateConfigCache();
immich.invalidateAll();
return NextResponse.json({ success: true, message: 'Saved successfully. Backup of previous version created.' }); return NextResponse.json({ success: true, message: 'Saved successfully. Backup of previous version created.' });
} catch (err) { } catch (err) {
console.error('[Admin] Failed to write settings.yaml:', err); console.error('[Admin] Failed to write settings.yaml:', err);

View File

@@ -434,7 +434,8 @@ class ImmichClient {
*/ */
invalidateAll(): void { invalidateAll(): void {
cache.clear(); cache.clear();
console.log('[Immich] 🔄 Full cache cleared via webhook'); this.hasLoggedAlbums = false;
console.log('[Immich] 🔄 Full cache cleared');
} }
/** /**