Skip to content

Commit 9bf7d00

Browse files
perf(web): compact changed-file directories once
1 parent 08a463e commit 9bf7d00

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

‎apps/web/src/lib/turnDiffTree.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,21 @@ describe("buildTurnDiffTree", () => {
8787
});
8888

8989
it("compacts only single-directory chains and stops at branch points", () => {
90+
expect(
91+
buildTurnDiffTree([
92+
{ path: "src/a/b/first.ts", kind: "modified", additions: 1, deletions: 0 },
93+
{ path: "src/c/d/second.ts", kind: "modified", additions: 2, deletions: 0 },
94+
]),
95+
).toMatchObject([
96+
{
97+
name: "src",
98+
children: [
99+
{ name: "a/b", path: "src/a/b", children: [{ name: "first.ts" }] },
100+
{ name: "c/d", path: "src/c/d", children: [{ name: "second.ts" }] },
101+
],
102+
},
103+
]);
104+
90105
const tree = buildTurnDiffTree([
91106
{ path: "apps/server/src/index.ts", kind: "modified", additions: 2, deletions: 1 },
92107
{ path: "apps/server/main.ts", kind: "modified", additions: 4, deletions: 0 },

‎apps/web/src/lib/turnDiffTree.ts‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,7 @@ function readStat(file: TurnDiffFileChange): TurnDiffStat | null {
5656
}
5757

5858
function compactDirectoryNode(node: TurnDiffTreeDirectoryNode): TurnDiffTreeDirectoryNode {
59-
const compactedChildren = node.children.map((child) =>
60-
child.kind === "directory" ? compactDirectoryNode(child) : child,
61-
);
62-
63-
let compactedNode: TurnDiffTreeDirectoryNode = {
64-
...node,
65-
children: compactedChildren,
66-
};
59+
let compactedNode = node;
6760

6861
while (compactedNode.children.length === 1 && compactedNode.children[0]?.kind === "directory") {
6962
const onlyChild = compactedNode.children[0];

0 commit comments

Comments
 (0)