Skip to content
TypeScript

perf(web): compact changed-file directories once (#27073)

Utkarsh Patile4d1edaabdce
diff --git a/apps/web/src/lib/turnDiffTree.test.ts b/apps/web/src/lib/turnDiffTree.test.ts
index 582dba9569a..bf792a80323 100644
--- a/apps/web/src/lib/turnDiffTree.test.ts
+++ b/apps/web/src/lib/turnDiffTree.test.ts
@@ -87,6 +87,21 @@ describe("buildTurnDiffTree", () => {
});
it("compacts only single-directory chains and stops at branch points", () => {
+ expect(
+ buildTurnDiffTree([
+ { path: "src/a/b/first.ts", kind: "modified", additions: 1, deletions: 0 },
+ { path: "src/c/d/second.ts", kind: "modified", additions: 2, deletions: 0 },
+ ]),
+ ).toMatchObject([
+ {
+ name: "src",
+ children: [
+ { name: "a/b", path: "src/a/b", children: [{ name: "first.ts" }] },
+ { name: "c/d", path: "src/c/d", children: [{ name: "second.ts" }] },
+ ],
+ },
+ ]);
+
const tree = buildTurnDiffTree([
{ path: "apps/server/src/index.ts", kind: "modified", additions: 2, deletions: 1 },
{ path: "apps/server/main.ts", kind: "modified", additions: 4, deletions: 0 },
diff --git a/apps/web/src/lib/turnDiffTree.ts b/apps/web/src/lib/turnDiffTree.ts
index e841e18ce24..7d491e15ccf 100644
--- a/apps/web/src/lib/turnDiffTree.ts
+++ b/apps/web/src/lib/turnDiffTree.ts
@@ -56,14 +56,7 @@ function readStat(file: TurnDiffFileChange): TurnDiffStat | null {
}
function compactDirectoryNode(node: TurnDiffTreeDirectoryNode): TurnDiffTreeDirectoryNode {
- const compactedChildren = node.children.map((child) =>
- child.kind === "directory" ? compactDirectoryNode(child) : child,
- );
-
- let compactedNode: TurnDiffTreeDirectoryNode = {
- ...node,
- children: compactedChildren,
- };
+ let compactedNode = node;
while (compactedNode.children.length === 1 && compactedNode.children[0]?.kind === "directory") {
const onlyChild = compactedNode.children[0];