perf: handle large workspace layout history (#3833)

This commit is contained in:
Neil
2026-05-30 11:49:05 -07:00
committed by GitHub
parent a4aa9f7e80
commit eaf8076e61
2 changed files with 40 additions and 2 deletions
+27
View File
@@ -10,6 +10,8 @@ import {
EXTERNAL_WORKTREE_VISIBILITY_ROLLOUT_AT
} from './worktree-ownership'
const LARGE_WORKSPACE_HISTORY_COUNT = 150_000
function makeRepo(overrides: Partial<Repo> = {}): Repo {
return {
id: 'repo-1',
@@ -172,6 +174,31 @@ describe('worktree ownership classification', () => {
).toBe('orca-managed')
})
it('builds known layouts from large workspace history lists', () => {
const repo = makeRepo()
const workspaceDirHistory = Array.from(
{ length: LARGE_WORKSPACE_HISTORY_COUNT },
(_, index) => ({
path: `/history/workspaces-${index}`,
nestWorkspaces: index % 2 === 0
})
)
const settings = makeSettings({
workspaceDir: '/new/workspaces',
workspaceDirHistory
})
const layouts = buildKnownOrcaWorkspaceLayouts(settings, repo)
expect(layouts).toHaveLength(LARGE_WORKSPACE_HISTORY_COUNT + 1)
expect(layouts[0]).toEqual({ path: '/new/workspaces', nestWorkspaces: true })
expect(layouts[1]).toEqual({ path: '/history/workspaces-0', nestWorkspaces: true })
expect(layouts.at(-1)).toEqual({
path: `/history/workspaces-${LARGE_WORKSPACE_HISTORY_COUNT - 1}`,
nestWorkspaces: false
})
})
it('handles Windows drive casing and separators', () => {
const repo = makeRepo({ path: 'C:\\repos\\App' })
const settings = makeSettings({ workspaceDir: 'C:\\Orca\\Workspaces' })
+13 -2
View File
@@ -49,11 +49,11 @@ export function buildKnownOrcaWorkspaceLayouts(
const layouts: OrcaWorkspaceLayout[] = []
if (!repo?.connectionId && settings.workspaceDir) {
layouts.push({ path: settings.workspaceDir, nestWorkspaces: settings.nestWorkspaces })
layouts.push(...(settings.workspaceDirHistory ?? []))
appendWorkspaceLayouts(layouts, settings.workspaceDirHistory ?? [])
}
const wslLayouts = repo ? buildWslWorkspaceLayouts(repo.path, settings) : []
layouts.push(...wslLayouts)
appendWorkspaceLayouts(layouts, wslLayouts)
const seen = new Set<string>()
return layouts.filter((layout) => {
@@ -66,6 +66,17 @@ export function buildKnownOrcaWorkspaceLayouts(
})
}
function appendWorkspaceLayouts(
target: OrcaWorkspaceLayout[],
source: readonly OrcaWorkspaceLayout[]
): void {
// Why: workspace history is persisted user data and can grow large enough
// for `push(...source)` to exceed the JavaScript call argument limit.
for (const layout of source) {
target.push(layout)
}
}
function buildWslWorkspaceLayouts(
repoPath: string,
settings: Pick<GlobalSettings, 'nestWorkspaces' | 'workspaceDirHistory'>