Skip to content

Commit 98bc998

Browse files
authored
fix(prs): bound refreshes by each tracker read (#19403)
1 parent 42da166 commit 98bc998

3 files changed

Lines changed: 38 additions & 1 deletion

File tree

‎apps/web/src/components/pullRequest/pullRequestList.logic.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { describe, expect, it } from "vite-plus/test";
99

1010
import {
1111
pullRequestHostActions,
12+
largestPullRequestReadCount,
1213
pullRequestQuickActions,
1314
filterPullRequestsByInvolvement,
1415
findScopedProject,
@@ -1759,3 +1760,24 @@ describe("pull request quick actions", () => {
17591760
]);
17601761
});
17611762
});
1763+
1764+
describe("refresh page size", () => {
1765+
const twoPagesAcrossFourRepositories = (provider: "github" | "gitlab") =>
1766+
["a", "b", "c", "d"].flatMap((name) =>
1767+
Array.from({ length: 198 }, (_, index) =>
1768+
entry({
1769+
number: index + 1,
1770+
provider: SourceControlProviderKind.make(provider),
1771+
repository: `pingdotgg/${name}`,
1772+
}),
1773+
),
1774+
);
1775+
1776+
it("asks each repository for its own rows where repositories are read one at a time", () => {
1777+
expect(largestPullRequestReadCount(twoPagesAcrossFourRepositories("gitlab"))).toBe(198);
1778+
});
1779+
1780+
it("asks for the whole host where one search reads every repository", () => {
1781+
expect(largestPullRequestReadCount(twoPagesAcrossFourRepositories("github"))).toBe(792);
1782+
});
1783+
});

‎apps/web/src/components/pullRequest/pullRequestList.logic.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,3 +1304,16 @@ export function pullRequestQuickActions(
13041304
: ["close", "merge"];
13051305
return forState.filter((action) => hostActions.has(action));
13061306
}
1307+
1308+
export function largestPullRequestReadCount(
1309+
entries: ReadonlyArray<EnvironmentPullRequestEntry>,
1310+
): number {
1311+
const counts = new Map<string, number>();
1312+
for (const entry of entries) {
1313+
const read = `${entry.environmentId} ${entry.host.toLowerCase()} ${
1314+
entry.provider === "github" ? "" : entry.repository.toLowerCase()
1315+
}`;
1316+
counts.set(read, (counts.get(read) ?? 0) + 1);
1317+
}
1318+
return Math.max(0, ...counts.values());
1319+
}

‎apps/web/src/routes/_chat.pull-requests.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ import {
9191
reusePullRequestEntries,
9292
settlePullRequestOverrides,
9393
pullRequestHostActions,
94+
largestPullRequestReadCount,
9495
} from "../components/pullRequest/pullRequestList.logic";
9596
import {
9697
pullRequestListPreferences,
@@ -1238,7 +1239,8 @@ function PullRequestsRouteView() {
12381239
return;
12391240
}
12401241
if (related.length > 0) listQuery.refresh(related);
1241-
const loadedCount = ordered?.key === filterKey ? ordered.entries.length : pageSize;
1242+
const loadedCount =
1243+
ordered?.key === filterKey ? largestPullRequestReadCount(ordered.entries) : pageSize;
12421244
setPage({
12431245
key: filterKey,
12441246
regrown: [],

0 commit comments

Comments
 (0)