fix: collect wide project group subtrees (#3692)
This commit is contained in:
@@ -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)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user