Skip to content

Commit 5a5b7bd

Browse files
committed
perf(server): keep the Azure summary read to one process
A linked thread polls the summary for every pull request each minute, and Azure had no summary read of its own, so the detail read behind it started paying for iterations and their changes to fill in a file count nothing on that path shows. Signed-off-by: Yordis Prieto <[email protected]>
1 parent ecaab33 commit 5a5b7bd

2 files changed

Lines changed: 82 additions & 0 deletions

File tree

‎apps/server/src/pullRequest/AzureDevOpsPullRequestProvider.test.ts‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,66 @@ function patchedPaths(patch: string): ReadonlyArray<string> {
134134
);
135135
}
136136

137+
describe("getChangeRequestSummary", () => {
138+
it.effect("costs the one pull request read, not the iterations changedFiles needs", () =>
139+
Effect.gen(function* () {
140+
let pullRequestReads = 0;
141+
142+
const provider = yield* make.pipe(
143+
Effect.provide(
144+
// listIterations and listIterationChanges are left unimplemented here, so a summary
145+
// that reached for either would die with UnimplementedError instead of this passing.
146+
Layer.mock(AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCli)({
147+
getPullRequest: () => {
148+
pullRequestReads += 1;
149+
return Effect.succeed(PULL_REQUEST);
150+
},
151+
}),
152+
),
153+
);
154+
155+
const readSummary = provider.getChangeRequestSummary;
156+
if (readSummary === undefined) return yield* Effect.die("summary read was not implemented");
157+
const summary = yield* readSummary({
158+
cwd: "/w",
159+
repository: "acme/web",
160+
host: "dev.azure.com",
161+
number: 7,
162+
});
163+
164+
expect(pullRequestReads).toBe(1);
165+
expect(summary.title).toBe(PULL_REQUEST.title);
166+
expect(summary.changedFiles).toBeUndefined();
167+
}),
168+
);
169+
});
170+
171+
describe("getChangeRequest", () => {
172+
it.effect("still reports the file count the detail panel needs", () =>
173+
Effect.gen(function* () {
174+
const provider = yield* make.pipe(
175+
Effect.provide(
176+
Layer.mock(AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCli)({
177+
getPullRequest: () => Effect.succeed(PULL_REQUEST),
178+
listIterations: () => Effect.succeed([ITERATION]),
179+
listIterationChanges: () =>
180+
Effect.succeed({ changes: [change("a.ts"), change("b.ts")], truncated: false }),
181+
}),
182+
),
183+
);
184+
185+
const detail = yield* provider.getChangeRequest({
186+
cwd: "/w",
187+
repository: "acme/web",
188+
host: "dev.azure.com",
189+
number: 7,
190+
});
191+
192+
expect(detail.changedFiles).toBe(2);
193+
}),
194+
);
195+
});
196+
137197
describe("getDiff reads", () => {
138198
it.effect("holds every reader together to one request's worth of processes", () =>
139199
Effect.gen(function* () {

‎apps/server/src/pullRequest/AzureDevOpsPullRequestProvider.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
type ProviderChangeRequest,
2222
type ProviderChangeRequestActivity,
2323
type ProviderChangeRequestDetail,
24+
type ProviderChangeRequestSummary,
2425
type ProviderDiffSlice,
2526
type PullRequestProviderApi,
2627
} from "./PullRequestProvider.ts";
@@ -327,6 +328,27 @@ export const make = Effect.gen(function* () {
327328
})),
328329
),
329330

331+
// The polled path a linked thread's row stays live on: one `az` read, no iterations or
332+
// changes behind it, since the file count that would cost is not shown here.
333+
getChangeRequestSummary: (input) =>
334+
cli.getPullRequest({ cwd: input.cwd, number: input.number }).pipe(
335+
Effect.mapError(fail("getChangeRequestSummary")),
336+
Effect.map((pullRequest): ProviderChangeRequestSummary => ({
337+
number: pullRequest.number,
338+
title: pullRequest.title,
339+
url: pullRequest.url,
340+
author: pullRequest.author,
341+
headBranch: pullRequest.headBranch,
342+
baseBranch: pullRequest.baseBranch,
343+
state: pullRequest.state,
344+
isDraft: pullRequest.isDraft,
345+
mergeability: pullRequest.mergeability,
346+
closedAt: pullRequest.state === "closed" ? pullRequest.closedAt : null,
347+
mergedAt: pullRequest.state === "merged" ? pullRequest.closedAt : null,
348+
updatedAt: pullRequest.updatedAt,
349+
})),
350+
),
351+
330352
getChangeRequest: (input) =>
331353
Effect.gen(function* () {
332354
const pullRequest = yield* cli.getPullRequest({ cwd: input.cwd, number: input.number });

0 commit comments

Comments
 (0)