Skip to content

Commit a958ffb

Browse files
rolag-itmp911de
authored andcommitted
Fix pagination with reactive fluent Querydsl query definition.
Pageable object was not passed to Query, so fetchPage retrieved erroneously the whole dataset as Page content. Closes #3892
1 parent c31872d commit a958ffb

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

Diff for: spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/ReactiveSpringDataMongodbQuery.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ Flux<K> fetch() {
9696
*/
9797
Mono<Page<K>> fetchPage(Pageable pageable) {
9898

99-
Mono<List<K>> content = createQuery().flatMapMany(it -> find.matching(it).all()).collectList();
99+
Mono<List<K>> content = createQuery().map(it -> it.with(pageable))
100+
.flatMapMany(it -> find.matching(it).all()).collectList();
100101

101102
return content.flatMap(it -> ReactivePageableExecutionUtils.getPage(it, pageable, fetchCount()));
102103
}

Diff for: spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/support/ReactiveQuerydslMongoPredicateExecutorTests.java

+2
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ public void findByShouldApplyPagination() {
400400
.as(StepVerifier::create) //
401401
.assertNext(it -> {
402402

403+
assertThat(it.getContent().size()).isEqualTo(1);
403404
assertThat(it.getTotalElements()).isEqualTo(2);
404405
assertThat(it.getContent()).contains(dave);
405406
}).verifyComplete();
@@ -409,6 +410,7 @@ public void findByShouldApplyPagination() {
409410
.as(StepVerifier::create) //
410411
.assertNext(it -> {
411412

413+
assertThat(it.getContent().size()).isEqualTo(1);
412414
assertThat(it.getTotalElements()).isEqualTo(2);
413415
assertThat(it.getContent()).contains(oliver);
414416
}).verifyComplete();

0 commit comments

Comments
 (0)