perf(library): persistent SPA shell, in-memory folder tree caching, and zero-flicker LRU thumbnail caching

This commit is contained in:
2026-10-07 12:05:58 +07:00
parent 3b4c49c41d
commit 1c7be6dfd4
3 changed files with 98 additions and 43 deletions
+10 -4
View File
@@ -146,7 +146,7 @@ export function canBrowseFolders(): boolean {
return typeof window !== 'undefined' && 'showDirectoryPicker' in window;
}
const THUMB_CACHE_MAX = 500;
const THUMB_CACHE_MAX = 5000;
const thumbCache = new Map<string, Blob>();
export function cacheThumb(id: string, blob: Blob): void {
@@ -278,14 +278,20 @@ function ask<T>(store: string, mode: IDBTransactionMode, run: (s: IDBObjectStore
);
}
// --- folders ---------------------------------------------------------------
let cachedFoldersList: LibraryFolder[] | null = null;
export function cachedFolders(): LibraryFolder[] {
return cachedFoldersList ?? [];
}
export async function listFolders(): Promise<LibraryFolder[]> {
try {
const rows = await ask<LibraryFolder[]>(FOLDERS, 'readonly', (s) => s.getAll());
return rows.sort((a, b) => a.name.localeCompare(b.name));
const sorted = rows.sort((a, b) => a.name.localeCompare(b.name));
cachedFoldersList = sorted;
return sorted;
} catch {
return [];
return cachedFoldersList ?? [];
}
}