Skip to content

Commit 2e22890

Browse files
updateRelatedChangeTypes: fix cubic behavior (#1042)
1 parent 11804ff commit 2e22890

2 files changed

Lines changed: 24 additions & 9 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "Fix cubic graph walk performance to quadratic",
4+
"packageName": "beachball",
5+
"email": "dstolee@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}

src/bump/updateRelatedChangeType.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,6 @@ export function updateRelatedChangeType(params: {
5353
while (queue.length > 0) {
5454
const { subjectPackage, changeType } = queue.shift()!;
5555

56-
if (visited.has(subjectPackage)) {
57-
continue;
58-
}
59-
60-
visited.add(subjectPackage);
61-
6256
// Step 1. Update change type of the subjectPackage according to the dependent change type propagation
6357
const packageInfo = packageInfos[subjectPackage];
6458
if (!packageInfo) {
@@ -68,18 +62,31 @@ export function updateRelatedChangeType(params: {
6862
const disallowedChangeTypes = packageInfo.combinedOptions?.disallowedChangeTypes ?? [];
6963

7064
if (subjectPackage !== entryPointPackageName) {
65+
const oldType = calculatedChangeTypes[subjectPackage];
7166
calculatedChangeTypes[subjectPackage] = getMaxChangeType(
72-
calculatedChangeTypes[subjectPackage],
67+
oldType,
7368
changeType,
7469
disallowedChangeTypes
7570
);
71+
72+
// We didn't change this type, so keep going.
73+
if (calculatedChangeTypes[subjectPackage] === oldType) {
74+
continue;
75+
}
7676
}
7777

7878
// Step 2. For all dependent packages of the current subjectPackage, place in queue to be updated at least to the "updatedChangeType"
7979
const dependentPackages = dependents[subjectPackage];
8080

8181
if (bumpDeps && dependentPackages?.length) {
82-
queue.push(...dependentPackages.map(pkg => ({ subjectPackage: pkg, changeType: updatedChangeType })));
82+
for (const dependentPackage of dependentPackages) {
83+
if (visited.has(dependentPackage)) {
84+
continue;
85+
}
86+
87+
visited.add(dependentPackage);
88+
queue.push(({ subjectPackage: dependentPackage, changeType: updatedChangeType }));
89+
}
8390
}
8491

8592
// TODO: when we do "locked", or "lock step" versioning, we could simply skip this grouped traversal,
@@ -91,7 +98,8 @@ export function updateRelatedChangeType(params: {
9198

9299
if (group) {
93100
for (const packageNameInGroup of group.packageNames) {
94-
if (!group.disallowedChangeTypes?.includes(updatedChangeType)) {
101+
if (!group.disallowedChangeTypes?.includes(updatedChangeType) && !visited.has(packageNameInGroup)) {
102+
visited.add(packageNameInGroup);
95103
queue.push({
96104
subjectPackage: packageNameInGroup,
97105
changeType: updatedChangeType,

0 commit comments

Comments
 (0)