perf(files): breadcrumb no longer blocks the listing; ancestors cached

Every folder navigation awaited rebuildBreadCrumb() — one sequential
fetch per ancestor level — before requesting the first page, so a
depth-8 folder paid ~8 RTTs of dead time before the content even
started loading. And nothing was cached: navigating between sibling
folders re-fetched the same ancestors every time.

- filesModel: session cache id → FolderItem for breadcrumb resolution
  (warm navigations rebuild the trail with zero fetches), invalidated
  on rename/move (single + batch) via invalidateFolderMeta. The trail
  is now built locally and committed atomically, guarded by a
  generation token so a rebuild superseded by a faster follow-up
  navigation can no longer interleave writes into the newer trail.
- filesView.loadFiles: the rebuild runs concurrently with the first
  page fetch; crumbs, history and title update when it resolves.
  Navigation latency becomes max(listing, ancestor chain) instead of
  their sum — and ~equal to the listing alone once the cache is warm.
  The home-folder fallback for inaccessible targets is preserved by
  reloading the listing when the rebuild had to reset app.currentPath.

https://claude.ai/code/session_01Dp3oWon5GBMVn4j3QXZdgx
This commit is contained in:
Claude
2026-06-10 11:39:56 +00:00
parent 71bdb653e0
commit 635ef8baf6
3 changed files with 91 additions and 10 deletions
@@ -10,6 +10,7 @@ import { showConfirmDialog, ui } from '../../app/ui.js';
import { getCsrfHeaders, getCsrfToken } from '../../core/csrf.js';
import { i18n } from '../../core/i18n.js';
import { notifications } from '../../core/notifications.js';
import { invalidateFolderMeta } from '../../model/filesModel.js';
import { triggerBrowserDownload } from '../../utils/download.js';
/**
@@ -892,6 +893,8 @@ const fileOps = {
});
if (response.ok) {
// Parent changed — drop the cached breadcrumb metadata
invalidateFolderMeta(folderId);
// Reload files after moving
await loadFiles();
ui.showNotification('Folder moved', 'Folder moved successfully');
@@ -955,6 +958,8 @@ const fileOps = {
const data = await res.json();
success += data.stats?.successful || 0;
errors += data.stats?.failed || 0;
// Parents changed — drop the cached breadcrumb metadata
for (const id of folderIds) invalidateFolderMeta(id);
}
} catch (err) {
console.error('Batch move error:', err);
@@ -1147,6 +1152,8 @@ const fileOps = {
console.log('Response status:', response.status);
if (response.ok) {
// Name changed — drop the cached breadcrumb metadata
invalidateFolderMeta(folderId);
ui.showNotification('Folder renamed', `Folder renamed to "${newName}"`);
} else {
const errorText = await response.text();