perf: skip folder-scope construction for separate repository imports (#19452)

* perf: skip folder-scope construction for separate repository imports

* refactor(project-groups): share one mode flag between scope skip and root guard

Also cover the separate-import path with real repo paths, which the throwing
getter test no longer exercises.

---------

Co-authored-by: m4air <m4air@m4airs-MacBook-Air.local>
Co-authored-by: Neil <4138956+nwparker@users.noreply.github.com>
This commit is contained in:
OrcaWin
2026-09-08 19:43:02 -07:00
committed by GitHub
co-authored by m4air Neil
parent 782c4618fd
commit 35bbc5ce5c
2 changed files with 34 additions and 6 deletions
@@ -138,7 +138,9 @@ describe('createNestedProjectGroupResolver', () => {
parentPath: '/workspace',
groupName: 'workspace',
mode: 'separate',
repoPaths: ['/workspace/services/api', '/workspace/services/worker'],
get repoPaths(): readonly string[] {
throw new Error('separate imports must not build unused folder scopes')
},
createGroup: () => {
throw new Error('should not create a group')
}
@@ -148,6 +150,30 @@ describe('createNestedProjectGroupResolver', () => {
expect(resolver.getCreatedGroups()).toEqual([])
})
it('leaves every separate-import repo ungrouped even when repo paths are supplied', () => {
const { groups, createGroup } = createGroupRecorder()
const repoPaths = [
'/workspace/services/api',
'/workspace/services/worker',
'/workspace/platform/packages/shared'
]
const resolver = createNestedProjectGroupResolver({
parentPath: '/workspace',
groupName: 'workspace',
mode: 'separate',
repoPaths,
createGroup
})
expect(repoPaths.map((repoPath) => resolver.getGroupForRepo(repoPath))).toEqual([
undefined,
undefined,
undefined
])
expect(resolver.getRootGroup()).toBeUndefined()
expect(groups).toEqual([])
})
it('preserves filesystem root parent paths when creating the root group', () => {
const groups: ProjectGroup[] = []
const resolver = createNestedProjectGroupResolver({
@@ -150,10 +150,12 @@ export function createNestedProjectGroupResolver(args: {
createGroup: (input: CreateGroupInput) => ProjectGroup
}): NestedProjectGroupResolver {
const createdGroups: ProjectGroup[] = []
const folderScopes = buildSparseFolderScopes({
parentPath: args.parentPath,
repoPaths: args.repoPaths ?? []
})
// Every folder-scope read sits behind ensureRootGroup, so outside group mode the scopes are
// unreachable. One flag drives both so the skip can never drift from the guard that justifies it.
const createsGroups = args.mode === 'group'
const folderScopes = createsGroups
? buildSparseFolderScopes({ parentPath: args.parentPath, repoPaths: args.repoPaths ?? [] })
: []
const folderScopesByRelativePath = new Map(
folderScopes.map((scope) => [scope.relativePath, scope])
)
@@ -161,7 +163,7 @@ export function createNestedProjectGroupResolver(args: {
let rootGroup: ProjectGroup | undefined
const ensureRootGroup = (): ProjectGroup | undefined => {
if (args.mode !== 'group') {
if (!createsGroups) {
return undefined
}
if (rootGroup) {