Skip to content

Commit 40526f9

Browse files
fix(server): a finished turn refreshes only its own project's PR listings (pingdotgg#35070)
1 parent bf13d60 commit 40526f9

4 files changed

Lines changed: 54 additions & 12 deletions

File tree

‎apps/server/src/git/linkCreatedPullRequest.test.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ it.effect(
169169
"refreshes PR readers after a push from a thread or project, but not a local commit",
170170
() =>
171171
Effect.gen(function* () {
172-
const refreshed: string[] = [];
172+
const refreshed: Array<[string, boolean | undefined]> = [];
173173
const layerDependencies = Layer.mergeAll(
174174
Layer.mock(Orchestrator.OrchestratorV2)({
175175
getThreadShell: () => Effect.succeed(v2PullRequestThread(thread)),
@@ -178,9 +178,9 @@ it.effect(
178178
listShells: () => Effect.succeed([project]),
179179
}),
180180
Layer.mock(PullRequestService.PullRequestService)({
181-
refreshAfterTurn: (id) =>
181+
refreshAfterTurn: (id, options) =>
182182
Effect.sync(() => {
183-
refreshed.push(id);
183+
refreshed.push([id, options?.pushed]);
184184
}),
185185
}),
186186
);
@@ -203,6 +203,10 @@ it.effect(
203203
{ cwd: "/draft-worktree", projectId: PROJECT_ID },
204204
{ push: { status: "pushed" } },
205205
).pipe(Effect.provide(layerDependencies));
206-
expect(refreshed).toEqual([PROJECT_ID, PROJECT_ID, PROJECT_ID]);
206+
expect(refreshed).toEqual([
207+
[PROJECT_ID, true],
208+
[PROJECT_ID, true],
209+
[PROJECT_ID, true],
210+
]);
207211
}),
208212
);

‎apps/server/src/git/refreshPushedPullRequests.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ export const refreshPushedPullRequests = Effect.fn("refreshPushedPullRequests")(
1616
const engine = yield* OrchestratorV2.OrchestratorV2;
1717
const thread = yield* engine.getThreadShell(input.threadId);
1818
if (thread !== null) {
19-
yield* pullRequests.refreshAfterTurn(thread.projectId);
19+
yield* pullRequests.refreshAfterTurn(thread.projectId, { pushed: true });
2020
return;
2121
}
2222
}
2323
if (input.projectId !== undefined) {
24-
yield* pullRequests.refreshAfterTurn(input.projectId);
24+
yield* pullRequests.refreshAfterTurn(input.projectId, { pushed: true });
2525
return;
2626
}
2727
const projects = yield* (yield* ProjectStore.ProjectStoreV2).listShells();
2828
yield* Effect.forEach(
2929
projects.filter((project) => project.workspaceRoot === input.cwd),
30-
(project) => pullRequests.refreshAfterTurn(project.id),
30+
(project) => pullRequests.refreshAfterTurn(project.id, { pushed: true }),
3131
{ discard: true },
3232
);
3333
},

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2671,6 +2671,40 @@ it.effect("does not revive old summaries when project epochs are evicted", () =>
26712671
}),
26722672
);
26732673

2674+
it.effect("a finished turn leaves another project's cached listing in place", () =>
2675+
Effect.gen(function* () {
2676+
const reads: string[] = [];
2677+
const service = yield* makeService({
2678+
projects: [
2679+
project({ id: "p1", title: "web", workspaceRoot: "/a", repository: "acme/web" }),
2680+
project({ id: "p2", title: "api", workspaceRoot: "/b", repository: "acme/api" }),
2681+
],
2682+
providers: [
2683+
fakePullRequestProvider(SourceControlProviderKind.make("github"), {
2684+
listChangeRequests: ({ repository }) => {
2685+
reads.push(repository);
2686+
return Effect.succeed({ items: [], truncated: false, continues: false });
2687+
},
2688+
}),
2689+
],
2690+
});
2691+
const webListing = { state: "open" as const, projectId: "p1" as ProjectId };
2692+
const everyListing = { state: "open" as const };
2693+
2694+
yield* service.list(webListing);
2695+
yield* service.list(everyListing);
2696+
reads.length = 0;
2697+
yield* service.refreshAfterTurn("p2" as ProjectId);
2698+
yield* service.list(webListing);
2699+
yield* service.list(everyListing);
2700+
assert.deepStrictEqual(reads, []);
2701+
2702+
yield* service.refreshAfterTurn("p2" as ProjectId, { pushed: true });
2703+
yield* service.list(everyListing);
2704+
assert.deepStrictEqual(reads.toSorted(), ["acme/api", "acme/web"]);
2705+
}),
2706+
);
2707+
26742708
it.effect("a refresh or a finished turn drops the provider's own change request reads", () =>
26752709
Effect.gen(function* () {
26762710
const forgotten: Array<{ readonly repository: string; readonly number?: number } | undefined> =

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,10 @@ export class PullRequestService extends Context.Service<
218218
input: PullRequestReportStateInput,
219219
) => Effect.Effect<void, PullRequestError>;
220220
readonly subscribeRefreshes: Stream.Stream<number>;
221-
readonly refreshAfterTurn: (projectId: ProjectId) => Effect.Effect<void>;
221+
readonly refreshAfterTurn: (
222+
projectId: ProjectId,
223+
options?: { readonly pushed?: boolean },
224+
) => Effect.Effect<void>;
222225
/** Project and remote lookups inside `effect` read once per filter, e.g. across one sync sweep. */
223226
readonly withSharedProjectReads: <A, E, R>(
224227
effect: Effect.Effect<A, E, R>,
@@ -3639,12 +3642,14 @@ export const make = Effect.gen(function* () {
36393642

36403643
const refreshAfterTurn: PullRequestService["Service"]["refreshAfterTurn"] = Effect.fn(
36413644
"PullRequestService.refreshAfterTurn",
3642-
)(function* (projectId) {
3645+
)(function* (projectId, options) {
36433646
// Everything the provider holds, not just the project's repository: a turn can touch a
36443647
// change request reached through another repository, and no epoch may move until those
36453648
// reads are gone, or a reader in between keeps the old one under the new epoch.
36463649
yield* forgetProviderReads();
3647-
listingsEpoch = ++epochCounter;
3650+
const epoch = ++epochCounter;
3651+
// A push can open or move a PR; a plain turn waits for the listing TTL to spare the API quota.
3652+
if (options?.pushed === true) listingsEpoch = epoch;
36483653
projectEpochs.delete(projectId);
36493654
if (projectEpochs.size >= REF_EPOCH_CAPACITY) {
36503655
const oldest = projectEpochs.keys().next().value;
@@ -3653,8 +3658,7 @@ export const make = Effect.gen(function* () {
36533658
projectEpochs.delete(oldest);
36543659
}
36553660
}
3656-
projectEpochs.set(projectId, listingsEpoch);
3657-
const epoch = listingsEpoch;
3661+
projectEpochs.set(projectId, epoch);
36583662
yield* readCache.invalidate(`project:${projectId}`);
36593663
yield* SubscriptionRef.set(pullRequestRefreshes, epoch);
36603664
});

0 commit comments

Comments
 (0)