@devries-cameron20 / t3code Mirror · read-only / commits / 4293433ecc
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 23, 21:45 UTC

perf(server): avoid rereading unchanged files in review previews (#13395)

shivam committed Sep 26, 2026 at 01:47 UTC 4293433eccbe6c6661acd020e584ae5d2234bf1e
2 files changed +41 -2
apps/server/src/vcs/GitVcsDriverCore.test.ts
+38
@@ -1449,6 +1449,44 @@ it.layer(TestLayer)("GitVcsDriver core integration", (it) => {
1449 }),
1450 );
1451
1452 + for (const splitIndex of [false, true]) {
1453 + it.effect(`keeps the preceding second cached in review previews (split: ${splitIndex})`, () =>
1454 + Effect.gen(function* () {
1455 + const cwd = yield* makeTmpDir();
1456 + yield* initRepoWithCommit(cwd);
1457 + const driver = yield* GitVcsDriver.GitVcsDriver;
1458 + const fs = yield* FileSystem.FileSystem;
1459 + const path = yield* Path.Path;
1460 + yield* writeTextFile(cwd, ".gitattributes", "stable.txt filter=probe\n");
1461 + yield* writeTextFile(cwd, "stable.txt", "unchanged\n");
1462 + yield* writeTextFile(
1463 + cwd,
1464 + ".git/filter.cjs",
1465 + 'require("node:fs").appendFileSync(".git/filter-runs", "read\\n"); process.stdin.pipe(process.stdout);',
1466 + );
1467 + yield* git(cwd, ["config", "filter.probe.clean", "node .git/filter.cjs"]);
1468 + yield* fs.utimes(path.join(cwd, "stable.txt"), 1_699_999_999.5, 1_699_999_999.5);
1469 + yield* git(cwd, ["add", "."]);
1470 + yield* git(cwd, ["commit", "-m", "cache stable file"]);
1471 + if (splitIndex) yield* git(cwd, ["update-index", "--split-index"]);
1472 + const indexPath = path.join(cwd, ".git", "index");
1473 + yield* fs.utimes(indexPath, 1_700_000_000, 1_700_000_000);
1474 + const originalIndex = yield* fs.readFile(indexPath);
1475 + const originalMtime = (yield* fs.stat(indexPath)).mtime;
1476 + yield* writeTextFile(cwd, ".git/filter-runs", "");
1477 + yield* writeTextFile(cwd, "untracked.txt", "new\n");
1478 + const preview = yield* driver.getReviewDiffPreview({ cwd });
1479 + assert.deepStrictEqual(
1480 + preview.sources.find((source) => source.kind === "working-tree")!.files,
1481 + [{ path: "untracked.txt", previousPath: null, additions: 1, deletions: 0 }],
1482 + );
1483 + assert.strictEqual(yield* fs.readFileString(path.join(cwd, ".git/filter-runs")), "");
1484 + assert.deepStrictEqual(yield* fs.readFile(indexPath), originalIndex);
1485 + assert.deepStrictEqual((yield* fs.stat(indexPath)).mtime, originalMtime);
1486 + }),
1487 + );
1488 + }
1489 +
1490 for (const [timestamp, splitIndex] of [
1491 [1_700_000_000, false],
1492 [1_700_000_000.9999, false],
apps/server/src/vcs/GitVcsDriverCore.ts
+3 -2
@@ -2358,9 +2358,10 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
2358 if (indexExists) {
2359 const { mtime } = yield* fileSystem.stat(indexPath);
2360 yield* fileSystem.copyFile(indexPath, tempIndexPath);
2361 - // A newer copy timestamp hides racily clean edits. Round down before Git reads or rewrites it.
2361 + // Node FileSystem.stat truncates bigint timestamps to milliseconds before creating its Date.
2362 + // Flooring preserves the source second without making preceding-second files racy.
2363 const indexTime = Option.isSome(mtime)
2363 - ? Math.max(0, Math.floor((mtime.value.getTime() - 1) / 1000))
2364 + ? Math.max(0, Math.floor(mtime.value.getTime() / 1000))
2365 : 0;
2366 yield* fileSystem.utimes(tempIndexPath, indexTime, indexTime);
2367 }