From 3d66c4eab5bb9dcbbb4f2ce260ed6ee55f4e52d3 Mon Sep 17 00:00:00 2001 From: Max Metral Date: Sun, 31 Mar 2024 23:28:50 -0400 Subject: [PATCH] fix(cursor): optimization was wrong, can't use empty cursor for completion --- src/asDataGenerator.ts | 5 ----- src/multiSourcePager.ts | 6 +----- src/queuePager.spec.ts | 12 ++++++------ 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/asDataGenerator.ts b/src/asDataGenerator.ts index b886be8..491c850 100644 --- a/src/asDataGenerator.ts +++ b/src/asDataGenerator.ts @@ -8,11 +8,6 @@ export function asDataGenerator( return { async *getGenerator(cursor: string | undefined) { - if (cursor === '') { - // The special empty string cursor indicates we should not fetch any more. - return; - } - let currentCursor = cursor; let continueFetching = true; diff --git a/src/multiSourcePager.ts b/src/multiSourcePager.ts index 6b1acc4..2d83032 100644 --- a/src/multiSourcePager.ts +++ b/src/multiSourcePager.ts @@ -47,8 +47,6 @@ export async function multiSourcePager>( index, key: dataSources[index].sortKey(item.value), }); - } else { - cursors[index] = ''; } })); @@ -65,9 +63,7 @@ export async function multiSourcePager>( // Fetch next item from the generator of the data source that the last item came from const nextResult = await generators[index].next(); - if (nextResult.done) { - cursors[index] = ''; - } else { + if (!nextResult.done) { queue.push({ result: nextResult.value, index, diff --git a/src/queuePager.spec.ts b/src/queuePager.spec.ts index 34846a5..54c7890 100644 --- a/src/queuePager.spec.ts +++ b/src/queuePager.spec.ts @@ -82,12 +82,12 @@ describe('multi source pager', () => { "type": "letter", }, { - "cursor": "WyIiLCIyMDIzLTAxLTA2VDAwOjAwOjAwLjAwMFojRkYiXQ==", + "cursor": "WyIyMDIzLTAxLTA1VDAwOjAwOjAwLjAwMFojRSIsIjIwMjMtMDEtMDZUMDA6MDA6MDAuMDAwWiNGRiJd", "data": "FF", "type": "letter", }, { - "cursor": "WyIiLCIyMDIzLTAxLTA3VDAwOjAwOjAwLjAwMFojR0ciXQ==", + "cursor": "WyIyMDIzLTAxLTA1VDAwOjAwOjAwLjAwMFojRSIsIjIwMjMtMDEtMDdUMDA6MDA6MDAuMDAwWiNHRyJd", "data": "GG", "type": "letter", }, @@ -98,7 +98,7 @@ describe('multi source pager', () => { expect(p4.results).toMatchInlineSnapshot(` [ { - "cursor": "WyIiLCIyMDIzLTAxLTA4VDAwOjAwOjAwLjAwMFojSEgiXQ==", + "cursor": "WyIyMDIzLTAxLTA1VDAwOjAwOjAwLjAwMFojRSIsIjIwMjMtMDEtMDhUMDA6MDA6MDAuMDAwWiNISCJd", "data": "HH", "type": "letter", }, @@ -137,17 +137,17 @@ describe('multi source pager', () => { "type": "letter", }, { - "cursor": "WyIyMDIzLTAxLTAzVDAwOjAwOjAwLjAwMFojQyIsIiJd", + "cursor": "WyIyMDIzLTAxLTAzVDAwOjAwOjAwLjAwMFojQyIsIjIwMjMtMDEtMDJUMDA6MDA6MDAuMDAwWiNCQkIiXQ==", "data": "C", "type": "letter", }, { - "cursor": "WyIyMDIzLTAxLTA0VDAwOjAwOjAwLjAwMFojRCIsIiJd", + "cursor": "WyIyMDIzLTAxLTA0VDAwOjAwOjAwLjAwMFojRCIsIjIwMjMtMDEtMDJUMDA6MDA6MDAuMDAwWiNCQkIiXQ==", "data": "D", "type": "letter", }, { - "cursor": "WyIyMDIzLTAxLTA1VDAwOjAwOjAwLjAwMFojRSIsIiJd", + "cursor": "WyIyMDIzLTAxLTA1VDAwOjAwOjAwLjAwMFojRSIsIjIwMjMtMDEtMDJUMDA6MDA6MDAuMDAwWiNCQkIiXQ==", "data": "E", "type": "letter", },