The best way to control Claude Code, Codex and more from any computer or phone
fix(pull-requests): a filtered list fills its page instead of waiting for a scroll (#23923)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 23, 2026 at 16:11 UTC
30465453489c170eb5532ab8a992477d2ecd1dc7
6 files changed
+312
-40
apps/mobile/src/features/pull-requests/PullRequestsScreen.tsx
+9
@@ -348,6 +348,15 @@ export function PullRequestsScreen(
348
onPress={() => void result.loadMore(true)}
349
/>
350
</View>
351
+ ) : result.hasMore ? (
352
+ // A filtered page can be too short to scroll, which leaves nothing to reach the end of.
353
+ <View className="items-center py-4">
354
+ <Button
355
+ label="Load more"
356
+ accessibilityLabel="Load more pull requests"
357
+ onPress={() => void result.loadMore()}
358
+ />
359
+ </View>
360
) : undefined
361
}
362
ListEmptyComponent={
apps/server/src/pullRequest/PullRequestService.test.ts
+85
@@ -3047,6 +3047,91 @@ it.effect("refuses a way of updating a branch that the host or the viewer does n
3047
}),
3048
);
3049
3050
+it.effect("keeps reading a host's thinned-out slices until a filtered page is full", () =>
3051
+ Effect.gen(function* () {
3052
+ const reads: Array<number> = [];
3053
+ const rows = Array.from({ length: 40 }, (_, index) => ({
3054
+ ...changeRequest(index + 1, `2026-07-${String(40 - index).padStart(2, "0")}T00:00:00Z`),
3055
+ labels: index % 2 === 0 ? [{ name: "bug", color: null }] : [],
3056
+ }));
3057
+ const service = yield* makeService({
3058
+ projects: [
3059
+ project({
3060
+ id: "p1",
3061
+ title: "on gitlab",
3062
+ workspaceRoot: "/a",
3063
+ repository: "group/project",
3064
+ provider: SourceControlProviderKind.make("gitlab"),
3065
+ }),
3066
+ ],
3067
+ providers: [
3068
+ fakeProvider(SourceControlProviderKind.make("gitlab"), {
3069
+ listChangeRequests: (input) => {
3070
+ const delivered = input.cursor?.delivered ?? 0;
3071
+ reads.push(delivered);
3072
+ return Effect.succeed({
3073
+ items: rows.slice(delivered, delivered + input.limit),
3074
+ truncated: delivered + input.limit < rows.length,
3075
+ continues: true,
3076
+ });
3077
+ },
3078
+ }),
3079
+ ],
3080
+ });
3081
+
3082
+ const bugs = yield* service.list({ state: "open", limit: 4, filters: { labels: [["bug"]] } });
3083
+ assert.deepStrictEqual(
3084
+ bugs.entries.map((entry) => entry.number),
3085
+ [1, 3, 5, 7],
3086
+ );
3087
+ assert.deepStrictEqual(reads, [0, 4]);
3088
+
3089
+ reads.length = 0;
3090
+ const none = yield* service.list({
3091
+ state: "open",
3092
+ limit: 4,
3093
+ filters: { labels: [["missing"]] },
3094
+ });
3095
+ assert.deepStrictEqual(none.entries, []);
3096
+ assert.strictEqual(reads.length, 5);
3097
+ assert.match(Object.values(none.nextCursors)[0] ?? "", /\|20\|/);
3098
+ }),
3099
+);
3100
+
3101
+it.effect("hands a host's own resume position back on the next read", () =>
3102
+ Effect.gen(function* () {
3103
+ const resumed: Array<string | undefined> = [];
3104
+ const service = yield* makeService({
3105
+ projects: [
3106
+ project({
3107
+ id: "p1",
3108
+ title: "on gitlab",
3109
+ workspaceRoot: "/a",
3110
+ repository: "group/project",
3111
+ provider: SourceControlProviderKind.make("gitlab"),
3112
+ }),
3113
+ ],
3114
+ providers: [
3115
+ fakeProvider(SourceControlProviderKind.make("gitlab"), {
3116
+ listChangeRequests: (input) => {
3117
+ resumed.push(input.cursor?.resumeAfter);
3118
+ return Effect.succeed({
3119
+ items: [changeRequest(resumed.length, "2026-07-02T00:00:00Z")],
3120
+ truncated: true,
3121
+ continues: true,
3122
+ resumeAfter: `2026-07-01T00:00:00.000Z~${resumed.length}`,
3123
+ });
3124
+ },
3125
+ }),
3126
+ ],
3127
+ });
3128
+
3129
+ const first = yield* service.list({ state: "open", limit: 1 });
3130
+ yield* service.list({ state: "open", limit: 1, cursors: first.nextCursors });
3131
+ assert.deepStrictEqual(resumed, [undefined, "2026-07-01T00:00:00.000Z~1"]);
3132
+ }),
3133
+);
3134
+
3135
it.effect("judges the review filter only on a host that summarises its reviews", () =>
3136
Effect.gen(function* () {
3137
const service = yield* makeService({
apps/server/src/pullRequest/PullRequestService.ts
+46
-6
@@ -123,6 +123,7 @@ function supersedesReading(current: PullRequestReading | undefined, next: PullRe
123
const DEFAULT_REPOSITORY_LIST_LIMIT = 99;
124
const REPOSITORY_CONCURRENCY = 12;
125
const REPOSITORY_SEARCH_CHUNK = 100;
126
+const FILTERED_LIST_READS = 5;
127
128
/**
129
* Every read leaves the process — a CLI per repository, against hosts whose limits are low
@@ -341,7 +342,7 @@ interface ListCursor extends ProviderListCursor {
342
}
343
344
const LIST_CURSOR_PATTERN =
344
- /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?(?:Z|[+-]\d{2}:\d{2}))\|(\d{1,9})\|(\d{1,9}(?:,\d{1,9})*)?$/;
345
+ /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?(?:Z|[+-]\d{2}:\d{2}))\|(\d{1,9})\|(\d{1,9}(?:,\d{1,9})*)?(?:\|([\w.:~+-]{1,128}))?$/;
346
347
function parseListCursor(raw: string): ListCursor | null {
348
const match = LIST_CURSOR_PATTERN.exec(raw);
@@ -351,6 +352,7 @@ function parseListCursor(raw: string): ListCursor | null {
352
updatedBefore: match[1]!,
353
delivered: Number(match[2]),
354
seenAt: seenAt === undefined ? [] : seenAt.split(",").map(Number),
355
+ ...(match[4] === undefined ? {} : { resumeAfter: match[4] }),
356
};
357
}
358
@@ -368,6 +370,7 @@ function nextListCursor(
370
delivered: ReadonlyArray<ProviderChangeRequest>,
371
/** A provider may consume malformed offset-paged rows that never appear in `delivered`. */
372
cursorAdvance = delivered.length,
373
+ resumeAfter?: string,
374
): string | null {
375
if (fetched.length === 0) return null;
376
// Taken from what the host answered rather than from what survived de-duplication: a slice can
@@ -375,7 +378,7 @@ function nextListCursor(
378
// repository's boring afternoon — and reading "nothing new" as "nothing left" would end the
379
// walk on the instant it was stuck on, with everything older unreachable for good.
380
const oldest = fetched.reduce((left, right) => (right.updatedAt < left.updatedAt ? right : left));
378
- return listCursorAt(previous, oldest.updatedAt, fetched, cursorAdvance);
381
+ return listCursorAt(previous, oldest.updatedAt, fetched, cursorAdvance, resumeAfter);
382
}
383
384
function listCursorAt(
@@ -383,12 +386,14 @@ function listCursorAt(
386
boundary: string,
387
fetched: ReadonlyArray<ProviderChangeRequest>,
388
deliveredCount: number,
389
+ resumeAfter?: string,
390
): string {
391
const seenAt = new Set([
392
...(previous?.updatedBefore === boundary ? previous.seenAt : []),
393
...fetched.filter((item) => item.updatedAt === boundary).map((item) => item.number),
394
]);
391
- return `${boundary}|${(previous?.delivered ?? 0) + deliveredCount}|${[...seenAt].join(",")}`;
395
+ const cursor = `${boundary}|${(previous?.delivered ?? 0) + deliveredCount}|${[...seenAt].join(",")}`;
396
+ return resumeAfter === undefined ? cursor : `${cursor}|${resumeAfter}`;
397
}
398
399
function isProviderUnusable(error: PullRequestProviderError): boolean {
@@ -1165,11 +1170,13 @@ export const make = Effect.gen(function* () {
1170
const cursorOf = (project: SupportedProject): ListCursor | undefined =>
1171
continuation?.get(project.cursorKey);
1172
1168
- const readRepository = (project: SupportedProject): Effect.Effect<RepositoryBatch> => {
1173
+ const readSlice = (
1174
+ project: SupportedProject,
1175
+ cursor: ListCursor | undefined,
1176
+ ): Effect.Effect<RepositoryBatch> => {
1177
{
1178
const viewer = viewers[project.host]!;
1179
const key = project.cursorKey;
1172
- const cursor = cursorOf(project);
1180
return project.api
1181
.listChangeRequests({
1182
cwd: project.project.workspaceRoot,
@@ -1188,6 +1195,7 @@ export const make = Effect.gen(function* () {
1195
updatedBefore: cursor.updatedBefore,
1196
delivered: cursor.delivered,
1197
seenAt: cursor.seenAt,
1198
+ resumeAfter: cursor.resumeAfter,
1199
},
1200
}),
1201
})
@@ -1214,7 +1222,13 @@ export const make = Effect.gen(function* () {
1222
truncated: page.truncated,
1223
nextCursor:
1224
page.continues && page.truncated
1217
- ? nextListCursor(cursor, page.items, items, page.cursorAdvance)
1225
+ ? nextListCursor(
1226
+ cursor,
1227
+ page.items,
1228
+ items,
1229
+ page.cursorAdvance,
1230
+ page.resumeAfter,
1231
+ )
1232
: null,
1233
};
1234
}),
@@ -1235,6 +1249,32 @@ export const make = Effect.gen(function* () {
1249
}
1250
};
1251
1252
+ // Filters a host cannot apply thin out the slices it hands over, so a repository keeps
1253
+ // reading until it has a page's worth or runs out. The reads are bounded: a filter that
1254
+ // matches nothing would otherwise walk the repository's whole history in one request.
1255
+ const readRepository = (project: SupportedProject): Effect.Effect<RepositoryBatch> => {
1256
+ const fill = (batch: RepositoryBatch, reads: number): Effect.Effect<RepositoryBatch> => {
1257
+ const cursor = batch.nextCursor === null ? null : parseListCursor(batch.nextCursor);
1258
+ if (
1259
+ input.filters === undefined ||
1260
+ cursor === null ||
1261
+ batch.entries.length >= limit ||
1262
+ reads >= FILTERED_LIST_READS
1263
+ ) {
1264
+ return Effect.succeed(batch);
1265
+ }
1266
+ return readSlice(project, cursor).pipe(
1267
+ Effect.flatMap((next) =>
1268
+ // A slice that failed keeps the cursor before it, so the reader can try again.
1269
+ next.errors.length > 0
1270
+ ? Effect.succeed(batch)
1271
+ : fill({ ...next, entries: [...batch.entries, ...next.entries] }, reads + 1),
1272
+ ),
1273
+ );
1274
+ };
1275
+ return readSlice(project, cursorOf(project)).pipe(Effect.flatMap((batch) => fill(batch, 1)));
1276
+ };
1277
+
1278
const readTogether = (
1279
chunk: ReadonlyArray<SupportedProject>,
1280
): Effect.Effect<ReadonlyArray<RepositoryBatch>> => {
packages/source-control-core/src/server/PullRequestProvider.ts
+7
@@ -144,6 +144,12 @@ export interface ProviderChangeRequestPage {
144
* may need to count malformed raw rows it consumed too.
145
*/
146
readonly cursorAdvance?: number;
147
+ /**
148
+ * Where a host that can only page from the top carries on: an opaque position past the last
149
+ * row delivered, handed back as the cursor's `resumeAfter`. Unlike a count of rows it survives
150
+ * rows above it closing between reads.
151
+ */
152
+ readonly resumeAfter?: string;
153
readonly continues: boolean;
154
}
155
@@ -160,6 +166,7 @@ export interface ProviderListCursor {
166
* applying their limit so a full page of tied updates does not repeat the same prefix.
167
*/
168
readonly seenAt?: ReadonlyArray<number> | undefined;
169
+ readonly resumeAfter?: string | undefined;
170
}
171
172
export interface ProviderBatchedChangeRequest extends ProviderChangeRequest {
packages/source-control-gitcafe/src/server/GitCafePullRequestProvider.test.ts
+79
-12
@@ -448,20 +448,87 @@ describe("GitCafePullRequestProvider", () => {
448
}).pipe(Effect.provide(server.layer));
449
});
450
451
- it.effect("leaves an author GitCafe has no profile for to be narrowed by login", () => {
452
- const server = fakeGitCafe({ "GET /repos/owner/repo/pulls": { items: [pull], next: null } });
451
+ it.effect("finds a GitHub-synced author's actor on their pull requests to narrow by it", () => {
452
+ const synced = {
453
+ ...pull,
454
+ number: 8,
455
+ author: { kind: "github", actorId: "act_synced", login: "Synced", avatarUrl: null },
456
+ };
457
+ const server = fakeGitCafe({
458
+ "GET /repos/owner/repo/pulls": (request: SentRequest) =>
459
+ request.query.get("authors") === '["act_synced"]'
460
+ ? { items: [synced], next: null }
461
+ : request.query.get("after") === null
462
+ ? { items: [pull], next: "o1" }
463
+ : { items: [synced], next: null },
464
+ });
465
return Effect.gen(function* () {
466
const provider = yield* GitCafePullRequestProvider.make;
455
- const page = yield* provider.listChangeRequests({
456
- ...target,
457
- state: "open",
458
- involvement: "all",
459
- viewer: "alice",
460
- limit: 10,
461
- filters: { author: "synced-only" },
462
- });
463
- assert.strictEqual(page.items.length, 1);
464
- assert.isNull(server.sent.at(-1)!.query.get("authors"));
467
+ const list = (author: string) =>
468
+ provider.listChangeRequests({
469
+ ...target,
470
+ state: "open",
471
+ involvement: "all",
472
+ viewer: "alice",
473
+ limit: 10,
474
+ filters: { author },
475
+ });
476
+ const page = yield* list("synced");
477
+ assert.deepStrictEqual(
478
+ page.items.map((item) => item.number),
479
+ [8],
480
+ );
481
+ assert.strictEqual(server.sent.at(-1)!.query.get("authors"), '["act_synced"]');
482
+ // Once seen, the actor is narrowed by straight away.
483
+ const sentBefore = server.sent.length;
484
+ yield* list("synced");
485
+ assert.deepStrictEqual(
486
+ server.sent.slice(sentBefore).map((request) => request.query.get("authors")),
487
+ [null, '["act_synced"]'],
488
+ );
489
+ // An author on none of the pages it reads gets nothing rather than unnarrowed rows a
490
+ // continuation would count against a different listing.
491
+ const missing = yield* list("nobody");
492
+ assert.deepStrictEqual(missing, { items: [], truncated: false, continues: false });
493
+ }).pipe(Effect.provide(server.layer));
494
+ });
495
+
496
+ it.effect("carries a listing on after the last row delivered when rows above it close", () => {
497
+ const created = (number: number) => `2026-09-12T12:00:0${9 - number}Z`;
498
+ let pulls = [1, 2, 3, 4, 5].map((number) => ({ ...pull, number, createdAt: created(number) }));
499
+ const server = fakeGitCafe({
500
+ "GET /repos/owner/repo/pulls": (request: SentRequest) => {
501
+ const offset = Number(request.query.get("after")?.slice(1) ?? 0);
502
+ const end = offset + Number(request.query.get("limit"));
503
+ return { items: pulls.slice(offset, end), next: end < pulls.length ? `o${end}` : null };
504
+ },
505
+ });
506
+ return Effect.gen(function* () {
507
+ const provider = yield* GitCafePullRequestProvider.make;
508
+ const list = (cursor?: { readonly resumeAfter?: string }) =>
509
+ provider.listChangeRequests({
510
+ ...target,
511
+ state: "open",
512
+ involvement: "all",
513
+ viewer: "alice",
514
+ limit: 2,
515
+ ...(cursor === undefined
516
+ ? {}
517
+ : { cursor: { updatedBefore: timestamp, delivered: 2, ...cursor } }),
518
+ });
519
+ const first = yield* list();
520
+ assert.deepStrictEqual(
521
+ first.items.map((item) => item.number),
522
+ [1, 2],
523
+ );
524
+ pulls = pulls.filter((candidate) => candidate.number !== 1);
525
+ const next = yield* list({ resumeAfter: first.resumeAfter! });
526
+ assert.deepStrictEqual(
527
+ next.items.map((item) => item.number),
528
+ [3, 4],
529
+ );
530
+ assert.isTrue(next.truncated);
531
+ assert.isTrue(next.continues);
532
}).pipe(Effect.provide(server.layer));
533
});
534
packages/source-control-gitcafe/src/server/GitCafePullRequestProvider.ts
+86
-22
@@ -47,6 +47,13 @@ const CAPABILITIES: PullRequestCapabilities = {
47
48
const PAGE_SIZE = 100;
49
const MAX_PAGES = 10;
50
+/**
51
+ * Pages read looking for a GitHub-synced author before a listing filtered by them gives up. The
52
+ * login only appears on their pull requests, so one older than this many is out of reach.
53
+ */
54
+const AUTHOR_DISCOVERY_PAGES = 5;
55
+/** Bounds the logins remembered from listings; a repository's authors fit many times over. */
56
+const KNOWN_AUTHORS_LIMIT = 10_000;
57
/** GitCafe's cap on paths per `/diff-files` read, and so one diff page. */
58
const DIFF_FILES_BATCH = 64;
59
/**
@@ -168,6 +175,13 @@ function stackHeadsCurrent(
175
);
176
}
177
178
+const POSITION = /^(.+)~(\d+)$/u;
179
+const parsePosition = (raw: string | undefined) => {
180
+ const match = raw === undefined ? null : POSITION.exec(raw);
181
+ const created = match === null ? Number.NaN : Date.parse(match[1]!);
182
+ return match === null || Number.isNaN(created) ? null : { created, number: Number(match[2]) };
183
+};
184
+
185
const withDetails = (
186
files: ReadonlyArray<Json.GitCafeDiffFile>,
187
details: ReadonlyArray<Json.GitCafeDiffFile>,
@@ -179,6 +193,18 @@ const withDetails = (
193
/** @public Service construction is part of the canonical Effect module API. */
194
export const make = Effect.gen(function* () {
195
const api = yield* GitCafeApi.GitCafeApi;
196
+ // GitCafe filters by actor id and has no lookup from a GitHub login to the actor sync made for
197
+ // it, so the pairs are learned from the pull requests every listing reads.
198
+ const knownAuthors = new Map<string, string>();
199
+ const authorKey = (host: string, login: string) =>
200
+ `${host.toLowerCase()}\n${login.toLowerCase()}`;
201
+ const learnAuthors = (host: string, pulls: ReadonlyArray<Json.GitCafePull>) => {
202
+ for (const { author } of pulls) {
203
+ if (author.kind !== "github") continue;
204
+ if (knownAuthors.size >= KNOWN_AUTHORS_LIMIT) knownAuthors.clear();
205
+ knownAuthors.set(authorKey(host, author.login), author.actorId);
206
+ }
207
+ };
208
209
const failure = (operation: string, detail: string, cause?: unknown) =>
210
new PullRequestProviderError({
@@ -263,8 +289,9 @@ export const make = Effect.gen(function* () {
289
});
290
291
/**
266
- * GitCafe filters by ids, so label names and the author's handle are looked up first. A name it
267
- * cannot resolve is left out, and the service narrows the rows by name instead.
292
+ * GitCafe filters by ids, so label names and the author's handle are looked up first. A label it
293
+ * cannot resolve is left out, and the service narrows the rows by name instead. An author it
294
+ * cannot resolve comes back as `unresolvedAuthor` for the listing to find.
295
*/
296
const listFilterParams = Effect.fn("GitCafePullRequestProvider.listFilterParams")(function* (
297
input: ProviderRepositoryRef & {
@@ -276,7 +303,7 @@ export const make = Effect.gen(function* () {
303
) {
304
const filters = input.filters;
305
const params: Array<readonly [string, string]> = [];
279
- if (filters === undefined) return params;
306
+ if (filters === undefined) return { params, unresolvedAuthor: null };
307
if (filters.draft !== undefined)
308
params.push([filters.draft === "only" ? "states" : "stateNots", encodeIds(["draft"])]);
309
const groups = filters.labels ?? [];
@@ -303,8 +330,8 @@ export const make = Effect.gen(function* () {
330
}
331
if (filters.author !== undefined && !input.authorNarrowed) {
332
const handle = resolvePullRequestAuthorFilter(filters.author, input.viewer);
306
- // A GitHub-synced author with no GitCafe profile has no handle here; their rows are
307
- // narrowed by login instead. A profile matches what GitHub sync authored for it too.
333
+ // A profile matches what GitHub sync authored for it too. A GitHub-synced author with no
334
+ // profile is known only by the actor on their pull requests.
335
const user = yield* read(
336
"listChangeRequests",
337
input,
@@ -319,9 +346,13 @@ export const make = Effect.gen(function* () {
346
: Effect.succeed(Option.none()),
347
}),
348
);
322
- if (Option.isSome(user)) params.push(["authors", encodeIds([user.value.actorId])]);
349
+ const actorId = Option.isSome(user)
350
+ ? user.value.actorId
351
+ : knownAuthors.get(authorKey(input.host, handle));
352
+ if (actorId === undefined) return { params, unresolvedAuthor: handle };
353
+ params.push(["authors", encodeIds([actorId])]);
354
}
324
- return params;
355
+ return { params, unresolvedAuthor: null };
356
});
357
358
const readComments = (operation: string, input: PullRef) =>
@@ -635,18 +666,12 @@ export const make = Effect.gen(function* () {
666
actorId = principal.value.actorId;
667
}
668
}
638
- const filterParams = yield* listFilterParams(
669
+ const { params: filterParams, unresolvedAuthor } = yield* listFilterParams(
670
{ ...input, authorNarrowed: actorId !== undefined && input.involvement === "authored" },
671
base,
672
);
642
- const limit = Math.max(1, input.limit);
643
- const items: Array<Json.GitCafePull> = [];
644
- let next: string | null = null;
645
- do {
646
- const query = new URLSearchParams({
647
- limit: String(Math.min(PAGE_SIZE, limit - items.length)),
648
- sort: "newest",
649
- });
673
+ const readPage = (rows: number, after: string | null) => {
674
+ const query = new URLSearchParams({ limit: String(rows), sort: "newest" });
675
if (input.state !== "all") query.set("state", input.state);
676
if (input.query?.trim()) query.set("q", input.query.trim());
677
for (const [key, value] of filterParams) query.set(key, value);
@@ -655,18 +680,57 @@ export const make = Effect.gen(function* () {
680
input.involvement === "reviewing" ? "reviewers" : "authors",
681
encodeIds([actorId]),
682
);
658
- if (next !== null) query.set("after", next);
659
- const page: typeof Json.GitCafePulls.Type = yield* read(
683
+ if (after !== null) query.set("after", after);
684
+ return read(
685
"listChangeRequests",
686
input,
687
{ path: `${base}/pulls?${query}` },
688
Json.GitCafePulls,
689
+ ).pipe(Effect.tap((page) => Effect.sync(() => learnAuthors(input.host, page.items))));
690
+ };
691
+ if (unresolvedAuthor !== null) {
692
+ // Rows are only ever handed out narrowed by actor, so a continuation always carries on
693
+ // the same narrowed listing.
694
+ const key = authorKey(input.host, unresolvedAuthor);
695
+ let after: string | null = null;
696
+ let pages = 0;
697
+ do {
698
+ const page: typeof Json.GitCafePulls.Type = yield* readPage(PAGE_SIZE, after);
699
+ pages += 1;
700
+ after = page.items.length === 0 ? null : page.next;
701
+ } while (!knownAuthors.has(key) && after !== null && pages < AUTHOR_DISCOVERY_PAGES);
702
+ const found = knownAuthors.get(key);
703
+ if (found === undefined)
704
+ return { items: [], truncated: after !== null, continues: false };
705
+ filterParams.push(["authors", encodeIds([found])]);
706
+ }
707
+ const limit = Math.max(1, input.limit);
708
+ const items: Array<Json.GitCafePull> = [];
709
+ // GitCafe pages by an opaque token and orders by creation, so a continuation reads from the
710
+ // top and keeps only the rows created after the last one delivered. A count of rows would
711
+ // skip one for every row above it that closed in between.
712
+ const resume = parsePosition(input.cursor?.resumeAfter);
713
+ const isNew = (pull: Json.GitCafePull) => {
714
+ if (resume === null) return true;
715
+ const created = Date.parse(pull.createdAt);
716
+ return (
717
+ created < resume.created || (created === resume.created && pull.number < resume.number)
718
+ );
719
+ };
720
+ let next: string | null = null;
721
+ do {
722
+ const page: typeof Json.GitCafePulls.Type = yield* readPage(
723
+ resume === null ? Math.min(PAGE_SIZE, limit - items.length) : PAGE_SIZE,
724
+ next,
725
);
665
- items.push(...page.items);
726
+ items.push(...page.items.filter(isNew));
727
next = page.items.length === 0 ? null : page.next;
728
} while (next !== null && items.length < limit);
729
+ const delivered = items.slice(0, limit);
730
+ const last = delivered.at(-1);
731
return {
669
- items: items.slice(0, limit).map((pull) => {
732
+ ...(last === undefined ? {} : { resumeAfter: `${last.createdAt}~${last.number}` }),
733
+ items: delivered.map((pull) => {
734
const item = Json.toChangeRequest(pull, input);
735
return input.involvement === "reviewing" && actorId !== undefined
736
? {
@@ -675,8 +739,8 @@ export const make = Effect.gen(function* () {
739
}
740
: item;
741
}),
678
- truncated: next !== null,
679
- continues: false,
742
+ truncated: next !== null || items.length > limit,
743
+ continues: true,
744
};
745
},
746
),