Skip to content

Commit 774469e

Browse files
committed
feat: support 'prefetch' in async pagination
1 parent 2c8c039 commit 774469e

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

src/it/java/io/weaviate/integration/PaginationITest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public void testAsyncPaginator() throws IOException, InterruptedException, Execu
143143

144144
// Act
145145
var objectCount = new AtomicInteger();
146-
var countAll = things.paginate(p -> p.pageSize(5))
146+
var countAll = things.paginate(p -> p.pageSize(5).prefetch(true))
147147
.forEach(__ -> objectCount.getAndIncrement());
148148

149149
// Assert

src/main/java/io/weaviate/client6/v1/api/collections/pagination/AsyncPaginator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ public AsyncPaginator(Builder<PropertiesT> builder) {
3636
return this.query.fetchObjects(fn).thenApply(QueryResponse::objects);
3737
});
3838

39-
this.resultSet = CompletableFuture.completedFuture(rs);
39+
this.resultSet = builder.prefetch ? rs.fetchNextPage() : CompletableFuture.completedFuture(rs);
4040
}
4141

4242
public CompletableFuture<Void> forEach(Consumer<WeaviateObject<PropertiesT, Object, QueryMetadata>> action) {
4343
return resultSet
44-
.thenCompose(AsyncResultSet::fetchNextPage)
44+
.thenCompose(rs -> rs.isEmpty() ? rs.fetchNextPage() : CompletableFuture.completedFuture(rs))
4545
.thenCompose(processPageAndAdvance(action));
4646
}
4747

0 commit comments

Comments
 (0)