TypeScript
fix(prs): bound refreshes by each tracker read (#19403)
Bilal Bakr98bc998e73ad
diff --git a/apps/web/src/components/pullRequest/pullRequestList.logic.test.ts b/apps/web/src/components/pullRequest/pullRequestList.logic.test.tsindex 4e4f04f2ec5..eaac1cba352 100644--- a/apps/web/src/components/pullRequest/pullRequestList.logic.test.ts+++ b/apps/web/src/components/pullRequest/pullRequestList.logic.test.ts@@ -9,6 +9,7 @@ import { describe, expect, it } from "vite-plus/test";import {pullRequestHostActions,+ largestPullRequestReadCount,pullRequestQuickActions,filterPullRequestsByInvolvement,findScopedProject,@@ -1759,3 +1760,24 @@ describe("pull request quick actions", () => {]);});});++describe("refresh page size", () => {+ const twoPagesAcrossFourRepositories = (provider: "github" | "gitlab") =>+ ["a", "b", "c", "d"].flatMap((name) =>+ Array.from({ length: 198 }, (_, index) =>+ entry({+ number: index + 1,+ provider: SourceControlProviderKind.make(provider),+ repository: `pingdotgg/${name}`,+ }),+ ),+ );++ it("asks each repository for its own rows where repositories are read one at a time", () => {+ expect(largestPullRequestReadCount(twoPagesAcrossFourRepositories("gitlab"))).toBe(198);+ });++ it("asks for the whole host where one search reads every repository", () => {+ expect(largestPullRequestReadCount(twoPagesAcrossFourRepositories("github"))).toBe(792);+ });+});diff --git a/apps/web/src/components/pullRequest/pullRequestList.logic.ts b/apps/web/src/components/pullRequest/pullRequestList.logic.tsindex f56929c5dbc..9f01d87601b 100644--- a/apps/web/src/components/pullRequest/pullRequestList.logic.ts+++ b/apps/web/src/components/pullRequest/pullRequestList.logic.ts@@ -1304,3 +1304,16 @@ export function pullRequestQuickActions(: ["close", "merge"];return forState.filter((action) => hostActions.has(action));}++export function largestPullRequestReadCount(+ entries: ReadonlyArray<EnvironmentPullRequestEntry>,+): number {+ const counts = new Map<string, number>();+ for (const entry of entries) {+ const read = `${entry.environmentId} ${entry.host.toLowerCase()} ${+ entry.provider === "github" ? "" : entry.repository.toLowerCase()+ }`;+ counts.set(read, (counts.get(read) ?? 0) + 1);+ }+ return Math.max(0, ...counts.values());+}diff --git a/apps/web/src/routes/_chat.pull-requests.tsx b/apps/web/src/routes/_chat.pull-requests.tsxindex f7154177f57..cb97e39f1da 100644--- a/apps/web/src/routes/_chat.pull-requests.tsx+++ b/apps/web/src/routes/_chat.pull-requests.tsx@@ -91,6 +91,7 @@ import {reusePullRequestEntries,settlePullRequestOverrides,pullRequestHostActions,+ largestPullRequestReadCount,} from "../components/pullRequest/pullRequestList.logic";import {pullRequestListPreferences,@@ -1238,7 +1239,8 @@ function PullRequestsRouteView() {return;}if (related.length > 0) listQuery.refresh(related);- const loadedCount = ordered?.key === filterKey ? ordered.entries.length : pageSize;+ const loadedCount =+ ordered?.key === filterKey ? largestPullRequestReadCount(ordered.entries) : pageSize;setPage({key: filterKey,regrown: [],