Skip to content

Commit 3fc5bdf

Browse files
Short-circuit findOpenPr after first matching PR is found
Avoid unnecessary GitHub API calls by returning immediately when a PR is found from the first matching headSelector, instead of iterating through all selectors and discarding the results. Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
1 parent 9f22fc7 commit 3fc5bdf

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

apps/server/src/git/Layers/GitManager.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -528,8 +528,6 @@ export const makeGitManager = Effect.gen(function* () {
528528

529529
const findOpenPr = (cwd: string, headSelectors: ReadonlyArray<string>) =>
530530
Effect.gen(function* () {
531-
const parsedByNumber = new Map<number, PullRequestInfo>();
532-
533531
for (const headSelector of headSelectors) {
534532
const pullRequests = yield* gitHubCli.listOpenPullRequests({
535533
cwd,
@@ -538,20 +536,19 @@ export const makeGitManager = Effect.gen(function* () {
538536
});
539537

540538
for (const pr of pullRequests) {
541-
parsedByNumber.set(pr.number, {
539+
return {
542540
number: pr.number,
543541
title: pr.title,
544542
url: pr.url,
545543
baseRefName: pr.baseRefName,
546544
headRefName: pr.headRefName,
547545
state: "open",
548546
updatedAt: null,
549-
} satisfies PullRequestInfo);
547+
} satisfies PullRequestInfo;
550548
}
551549
}
552550

553-
const [first] = parsedByNumber.values();
554-
return first ?? null;
551+
return null;
555552
});
556553

557554
const findLatestPr = (cwd: string, details: { branch: string; upstreamRef: string | null }) =>

0 commit comments

Comments
 (0)