authorgravatar for 91240327+shivamhwp@users.noreply.github.comshivam <91240327+shivamhwp@users.noreply.github.com> 2026-09-26 01:47:54+05:30
committergravatar for noreply@github.comGitHub <noreply@github.com> 2026-09-25 13:17:54-07:00
log4293433eccbe6c6661acd020e584ae5d2234bf1e
treeed394be84c9cba6ce97568aa6854f771865d84bb
parentf5bd2fddbf00021b29c1dbe32210240886806718
signature Signed by PGP key B5690EEEBB952194

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


2 files changed, 41 insertions(+), 2 deletions(-)

apps/server/src/vcs/GitVcsDriverCore.test.ts+38
......@@ -1449,6 +1449,44 @@ it.layer(TestLayer)("GitVcsDriver core integration", (it) => {
14491449 }),
14501450 );
14511451
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
14521490 for (const [timestamp, splitIndex] of [
14531491 [1_700_000_000, false],
14541492 [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*
23582358 if (indexExists) {
23592359 const { mtime } = yield* fileSystem.stat(indexPath);
23602360 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.
23622363 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))
23642365 : 0;
23652366 yield* fileSystem.utimes(tempIndexPath, indexTime, indexTime);
23662367 }