fix: collect wide project group subtrees (#3692)

This commit is contained in:
Neil
2026-05-30 06:24:07 -07:00
committed by GitHub
parent dd70ec2551
commit 97990163b8
2 changed files with 24 additions and 5 deletions
+16
View File
@@ -112,4 +112,20 @@ describe('project-groups', () => {
].sort()
).toEqual(['child', 'grandchild', 'root'])
})
it('collects wide descendant groups without overflowing argument limits', () => {
const groups = [
{ id: 'root', parentGroupId: null },
...Array.from({ length: 130_000 }, (_, index) => ({
id: `child-${index}`,
parentGroupId: 'root'
}))
]
const subtreeIds = getProjectGroupSubtreeIds(groups, 'root')
expect(subtreeIds.size).toBe(130_001)
expect(subtreeIds.has('root')).toBe(true)
expect(subtreeIds.has('child-129999')).toBe(true)
})
})
+8 -5
View File
@@ -105,10 +105,9 @@ export function getProjectGroupSubtreeIds(
if (!group.parentGroupId) {
continue
}
childGroupsByParentId.set(group.parentGroupId, [
...(childGroupsByParentId.get(group.parentGroupId) ?? []),
group.id
])
const children = childGroupsByParentId.get(group.parentGroupId) ?? []
children.push(group.id)
childGroupsByParentId.set(group.parentGroupId, children)
}
const subtreeIds = new Set<string>()
@@ -119,7 +118,11 @@ export function getProjectGroupSubtreeIds(
continue
}
subtreeIds.add(groupId)
pending.push(...(childGroupsByParentId.get(groupId) ?? []))
// Why: imported project-group trees can be very wide; `push(...children)`
// can exceed V8's argument limit while collecting descendants.
for (const childGroupId of childGroupsByParentId.get(groupId) ?? []) {
pending.push(childGroupId)
}
}
return subtreeIds
}