Skip to content
TypeScript

perf(server): avoid remote enumeration during status reads (#19802)

IfkumRfnlc1c6be8b87f8
diff --git a/apps/server/src/vcs/GitVcsDriverCore.test.ts b/apps/server/src/vcs/GitVcsDriverCore.test.ts
index cc957d67eff..ddc5767d6aa 100644
--- a/apps/server/src/vcs/GitVcsDriverCore.test.ts
+++ b/apps/server/src/vcs/GitVcsDriverCore.test.ts
@@ -3542,14 +3542,16 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
yield* git(cwd, ["symbolic-ref", "refs/remotes/origin/HEAD", "refs/remotes/origin/trunk"]);
const delegate = yield* ChildProcessSpawner.ChildProcessSpawner;
+ const commands: ReadonlyArray<string>[] = [];
let originHeadReads = 0;
let failFirstOriginHead = false;
const spawner = ChildProcessSpawner.make((command) =>
Effect.gen(function* () {
- if (
- ChildProcess.isStandardCommand(command) &&
- command.args.join(" ") === "symbolic-ref refs/remotes/origin/HEAD"
- ) {
+ if (!ChildProcess.isStandardCommand(command)) {
+ return yield* Effect.die("expected a standard Git command");
+ }
+ commands.push(command.args);
+ if (command.args.join(" ") === "symbolic-ref refs/remotes/origin/HEAD") {
originHeadReads++;
if (failFirstOriginHead && originHeadReads === 1) return makeNonRepositoryHandle();
}
@@ -3565,12 +3567,19 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
assert.equal(status.isRepo, true);
assert.equal(status.branch, "feature/remote-status");
assert.equal(status.defaultBranch, "trunk");
+ assert.equal(status.isDefaultBranch, false);
+ assert.equal(status.upstreamRef, "origin/feature/remote-status");
assert.equal(status.hasUpstream, true);
assert.equal(status.aheadCount, 0);
assert.equal(status.behindCount, 0);
assert.equal(status.aheadOfDefaultCount, 1);
assert.notProperty(status, "workingTree");
assert.notProperty(status, "hasWorkingTreeChanges");
+ assert.deepEqual(
+ commands.filter((args) => args.length === 1 && args[0] === "remote"),
+ [],
+ `cached remote status should not enumerate remotes: ${JSON.stringify(commands)}`,
+ );
assert.equal(originHeadReads, 1);
// With no main/master fallback, the retry must resolve trunk to preserve the ahead count.
diff --git a/apps/server/src/vcs/GitVcsDriverCore.ts b/apps/server/src/vcs/GitVcsDriverCore.ts
index 0957df6e037..0727e2ca9c5 100644
--- a/apps/server/src/vcs/GitVcsDriverCore.ts
+++ b/apps/server/src/vcs/GitVcsDriverCore.ts
@@ -1233,7 +1233,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
});
});
- const resolveCurrentUpstream = Effect.fn("resolveCurrentUpstream")(function* (cwd: string) {
+ const readCurrentUpstreamRef = Effect.fn("readCurrentUpstreamRef")(function* (cwd: string) {
const upstreamRef = yield* runGitStdout(
"GitVcsDriver.resolveCurrentUpstream",
cwd,
@@ -1244,6 +1244,17 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
if (upstreamRef.length === 0 || upstreamRef === "@{upstream}") {
return null;
}
+ return upstreamRef;
+ });
+
+ const resolveCurrentUpstream = Effect.fn("resolveCurrentUpstream")(function* (
+ cwd: string,
+ knownUpstreamRef?: string,
+ ) {
+ const upstreamRef = knownUpstreamRef ?? (yield* readCurrentUpstreamRef(cwd));
+ if (upstreamRef === null) {
+ return null;
+ }
const remoteNames = yield* runGitStdout("GitVcsDriver.listRemoteNames", cwd, ["remote"]).pipe(
Effect.map(parseRemoteNames),
@@ -1923,8 +1934,15 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
const branchValue = branchResult.stdout.trim();
branch = branchValue.length > 0 && branchValue !== "HEAD" ? branchValue : null;
}
- const upstream = yield* resolveCurrentUpstream(cwd);
- const upstreamRef = upstream?.upstreamRef ?? null;
+ const currentUpstreamRef = yield* readCurrentUpstreamRef(cwd);
+ let upstreamRef =
+ currentUpstreamRef === null
+ ? null
+ : (parseUpstreamRefByFirstSeparator(currentUpstreamRef)?.upstreamRef ?? null);
+ // Trimming a remote that starts with Unicode whitespace can leave a leading slash.
+ if (currentUpstreamRef?.startsWith("/")) {
+ upstreamRef = (yield* resolveCurrentUpstream(cwd, currentUpstreamRef))?.upstreamRef ?? null;
+ }
let aheadCount = 0;
let behindCount = 0;