@devries-cameron20 / t3code Mirror · read-only / commits / 3883ed544c
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 21, 13:30 UTC

perf(azure-devops): opening a pull request no longer reads it twice (#29918)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Alex Vallone committed Nov 14, 2026 at 16:17 UTC 3883ed544c3ae044ad5c002fbd1e4308b0f3ec2d
2 files changed +103 -21
packages/source-control-azure-devops/src/server/AzureDevOpsPullRequestProvider.test.ts
+44
@@ -1,5 +1,7 @@
1 import { describe, expect, it } from "@effect/vitest";
2 +import * as Deferred from "effect/Deferred";
3 import * as Effect from "effect/Effect";
4 +import * as Fiber from "effect/Fiber";
5 import * as Layer from "effect/Layer";
6 import type { PullRequestCheck, PullRequestCheckStatus } from "@t3tools/contracts";
7
@@ -195,6 +197,48 @@ describe("getChangeRequest", () => {
197 expect(detail.changedFiles).toBe(0);
198 }),
199 );
200 +
201 + it.effect(
202 + "reads the pull request once for overlapping detail and conversation, then its diff",
203 + () =>
204 + Effect.gen(function* () {
205 + let reads = 0;
206 + const release = yield* Deferred.make<void>();
207 + const provider = yield* make.pipe(
208 + Effect.provide(
209 + Layer.mock(AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCli)({
210 + getPullRequest: () =>
211 + Effect.sync(() => {
212 + reads += 1;
213 + }).pipe(Effect.andThen(Deferred.await(release)), Effect.as(PULL_REQUEST)),
214 + listIterations: () => Effect.succeed([ITERATION]),
215 + listIterationChanges: () =>
216 + Effect.succeed({ changes: [change("a.ts")], truncated: false }),
217 + readItemContent: () =>
218 + Effect.succeed({ contents: side("new", 2, 4), isBinary: false }),
219 + ...NO_BLOBS,
220 + listPolicyChecks: () => Effect.succeed([]),
221 + listThreads: () => Effect.succeed([]),
222 + }),
223 + ),
224 + );
225 + const input = { cwd: "/w", repository: "acme/web", host: "dev.azure.com", number: 7 };
226 +
227 + // Clients request detail and conversation together; both start before the read returns.
228 + const detail = yield* Effect.forkChild(provider.getChangeRequest(input), {
229 + startImmediately: true,
230 + });
231 + const activity = yield* Effect.forkChild(provider.getChangeRequestActivity(input), {
232 + startImmediately: true,
233 + });
234 + yield* Deferred.succeed(release, undefined);
235 + yield* Fiber.join(detail);
236 + yield* Fiber.join(activity);
237 + yield* provider.getDiff(input);
238 +
239 + expect(reads).toBe(1);
240 + }),
241 + );
242 });
243
244 describe("policy checks", () => {
packages/source-control-azure-devops/src/server/AzureDevOpsPullRequestProvider.ts
+59 -21
@@ -1,5 +1,7 @@
1 import { resolvePullRequestAuthorFilter, SourceControlProviderKind } from "@t3tools/contracts";
2 +import * as Deferred from "effect/Deferred";
3 import * as Effect from "effect/Effect";
4 +import * as Exit from "effect/Exit";
5 import * as Semaphore from "effect/Semaphore";
6 import { rollupCheckStatuses } from "@t3tools/source-control-core/server/pullRequestChecks";
7 import type { PullRequestCapabilities, PullRequestViewerPermissions } from "@t3tools/contracts";
@@ -199,26 +201,62 @@ export const make = Effect.gen(function* () {
201
202 const EMPTY_DIFF_SLICE: ProviderDiffSlice = { patch: "", truncated: false, nextCursor: null };
203
202 - // PR locations are immutable; caching avoids full PR reads for viewed-file checks.
204 + // PR locations are immutable; every pull request read records one so later reads can skip it.
205 const locations = new Map<string, AzureDevOpsRepositoryLocation>();
206 // A pushed iteration never changes, so neither do its commits nor its change list.
207 const knownIterations = new Map<string, ReadonlyArray<AzureDevOpsIteration>>();
208 const iterationChanges = new Map<string, AzureDevOpsPullRequestCli.AzureDevOpsIterationChanges>();
209
208 - const locationOf = (input: { readonly cwd: string; readonly number: number }) => {
209 - const key = `${input.cwd} ${input.number}`;
210 - const held = recall(locations, key);
211 - if (held !== undefined) return Effect.succeed(held);
212 - return cli
213 - .getPullRequest({ cwd: input.cwd, number: input.number })
214 - .pipe(
215 - Effect.map((pullRequest) =>
216 - pullRequest.location === null
217 - ? null
218 - : remember(locations, LOCATION_CACHE_CAPACITY, key, pullRequest.location),
210 + // Reads still running, so a location lookup joins one instead of spawning its own az process.
211 + const pendingLocations = new Map<
212 + string,
213 + Deferred.Deferred<
214 + AzureDevOpsRepositoryLocation | null,
215 + AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCliError
216 + >
217 + >();
218 +
219 + const readPullRequest = (input: { readonly cwd: string; readonly number: number }) =>
220 + Effect.suspend(() => {
221 + const key = `${input.cwd} ${input.number}`;
222 + const pending = Deferred.makeUnsafe<
223 + AzureDevOpsRepositoryLocation | null,
224 + AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCliError
225 + >();
226 + pendingLocations.set(key, pending);
227 + return cli.getPullRequest({ cwd: input.cwd, number: input.number }).pipe(
228 + Effect.map((pullRequest) => {
229 + if (pullRequest.location !== null) {
230 + remember(locations, LOCATION_CACHE_CAPACITY, key, pullRequest.location);
231 + }
232 + return pullRequest;
233 + }),
234 + Effect.onExit((exit) =>
235 + Effect.sync(() => {
236 + if (pendingLocations.get(key) === pending) pendingLocations.delete(key);
237 + Deferred.doneUnsafe(
238 + pending,
239 + Exit.map(exit, (pullRequest) => pullRequest.location),
240 + );
241 + }),
242 ),
243 );
221 - };
244 + });
245 +
246 + const locationOf = (input: { readonly cwd: string; readonly number: number }) =>
247 + Effect.suspend(() => {
248 + const key = `${input.cwd} ${input.number}`;
249 + const held = recall(locations, key);
250 + if (held !== undefined) return Effect.succeed(held);
251 + const ownRead = readPullRequest(input).pipe(
252 + Effect.map((pullRequest) => pullRequest.location),
253 + );
254 + const pending = pendingLocations.get(key);
255 + // A read that failed or was interrupted under another request is retried here.
256 + return pending === undefined
257 + ? ownRead
258 + : Deferred.await(pending).pipe(Effect.catchCause(() => ownRead));
259 + });
260
261 const readChecks = (input: { readonly cwd: string }, pullRequest: AzureDevOpsPullRequest) =>
262 cli.listPolicyChecks({
@@ -364,7 +402,7 @@ export const make = Effect.gen(function* () {
402 ),
403
404 getChangeRequestPreview: (input) =>
367 - cli.getPullRequest({ cwd: input.cwd, number: input.number }).pipe(
405 + readPullRequest(input).pipe(
406 Effect.mapError(fail("getChangeRequestPreview")),
407 Effect.map((pullRequest) => ({
408 number: pullRequest.number,
@@ -379,7 +417,7 @@ export const make = Effect.gen(function* () {
417
418 getChangeRequestChecks: Effect.fn("AzureDevOpsPullRequestProvider.getChangeRequestChecks")(
419 function* (input) {
382 - const pullRequest = yield* cli.getPullRequest({ cwd: input.cwd, number: input.number });
420 + const pullRequest = yield* readPullRequest(input);
421 const checks = yield* readChecks(input, pullRequest);
422 return { state: pullRequest.state, checks };
423 },
@@ -388,7 +426,7 @@ export const make = Effect.gen(function* () {
426
427 getChangeRequestSummary: Effect.fn("AzureDevOpsPullRequestProvider.getChangeRequestSummary")(
428 function* (input) {
391 - const pullRequest = yield* cli.getPullRequest({ cwd: input.cwd, number: input.number });
429 + const pullRequest = yield* readPullRequest(input);
430 // Undefined keeps the last known state; null would claim no checks exist.
431 const checksState = yield* readChecks(input, pullRequest).pipe(
432 Effect.map((checks) => rollupCheckStatuses(checks.map((check) => check.status))),
@@ -404,7 +442,7 @@ export const make = Effect.gen(function* () {
442
443 getChangeRequest: Effect.fn("AzureDevOpsPullRequestProvider.getChangeRequest")(
444 function* (input) {
407 - const pullRequest = yield* cli.getPullRequest({ cwd: input.cwd, number: input.number });
445 + const pullRequest = yield* readPullRequest(input);
446 const location = pullRequest.location;
447 const iterations =
448 location === null
@@ -449,15 +487,15 @@ export const make = Effect.gen(function* () {
487 ),
488
489 getChangeRequestActivity: (input) =>
452 - cli.getPullRequest({ cwd: input.cwd, number: input.number }).pipe(
490 + locationOf(input).pipe(
491 Effect.mapError(fail("getChangeRequestActivity")),
454 - Effect.flatMap((pullRequest) =>
455 - (pullRequest.location === null
492 + Effect.flatMap((location) =>
493 + (location === null
494 ? Effect.succeed({ comments: [], truncated: true })
495 : cli
496 .listThreads({
497 cwd: input.cwd,
460 - location: pullRequest.location,
498 + location,
499 number: input.number,
500 })
501 .pipe(