perf(library): persistent SPA shell, in-memory folder tree caching, and zero-flicker LRU thumbnail caching
This commit is contained in:
@@ -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 ?? [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user