Files
orca/src/main/git/git-upstream-status-read-owner.ts
T
Neil eb3f6838af perf: coalesce git upstream status reads (#11697)
* perf: coalesce git upstream status reads

* fix(git): repair upstream lease key imports and guard its field list

The read owner imported the shared/types barrel deleted by #14447, and its
push-target key hand-enumerated fields, so a new GitPushTarget field would
silently share a lease between two different targets. The destructure now
fails to compile if a field is added. Lease tests moved into their own file
after #14728 split ssh-git-provider.test.ts.

* test(git): enforce native upstream coalescing in CI

The 10-caller benchmark only runs under ORCA_GIT_UPSTREAM_COALESCING_BENCH_JSON,
so nothing in CI failed when the native/WSL lease was bypassed. Route status.ts
through invalidateGitUpstreamStatusReads so the export has a production caller.
2026-08-15 23:24:05 -07:00

46 lines
1.7 KiB
TypeScript

import type { GitUpstreamStatus } from '../../shared/git-status-types'
import type { GitPushTarget } from '../../shared/worktree/types'
import { InFlightPromiseDedupe, stableInFlightKey } from '../../shared/in-flight-promise-dedupe'
/**
* Why the exhaustive destructure: stableInFlightKey is JSON.stringify, which is not
* key-order stable, so push-target fields must be listed in a fixed order. Spreading
* the remainder into Record<string, never> makes a newly added GitPushTarget field a
* compile error instead of a silently shared lease between two different targets.
*/
function pushTargetKeyParts(pushTarget: GitPushTarget): readonly unknown[] {
const { remoteName, branchName, remoteUrl, remoteCreated, ...rest } = pushTarget
const exhaustive: Record<string, never> = rest
void exhaustive
return ['explicit-target', remoteName, branchName, remoteUrl ?? null, remoteCreated ?? null]
}
export type GitUpstreamStatusExecutionIdentity =
| { kind: 'native' }
| { kind: 'wsl'; distro: string }
| { kind: 'ssh-provider' }
export class GitUpstreamStatusReadOwner {
private readonly inFlightReads = new InFlightPromiseDedupe<GitUpstreamStatus>()
read(
executionIdentity: GitUpstreamStatusExecutionIdentity,
worktreePath: string,
pushTarget: GitPushTarget | undefined,
load: () => Promise<GitUpstreamStatus>
): Promise<GitUpstreamStatus> {
const key = stableInFlightKey([
executionIdentity,
worktreePath,
pushTarget ? pushTargetKeyParts(pushTarget) : ['configured-upstream']
])
return this.inFlightReads.run(key, load)
}
invalidate(): void {
this.inFlightReads.clear()
}
}
export const nativeAndWslGitUpstreamStatusReadOwner = new GitUpstreamStatusReadOwner()