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
This commit is contained in:
rolag-it
2021-11-29 15:00:05 +01:00
committed by Mark Paluch
parent c31872d979
commit a958ffb5c8
2 changed files with 4 additions and 1 deletions

View File

@@ -96,7 +96,8 @@ class ReactiveSpringDataMongodbQuery<K> extends SpringDataMongodbQuerySupport<Re
*/
Mono<Page<K>> fetchPage(Pageable pageable) {
Mono<List<K>> content = createQuery().flatMapMany(it -> find.matching(it).all()).collectList();
Mono<List<K>> content = createQuery().map(it -> it.with(pageable))
.flatMapMany(it -> find.matching(it).all()).collectList();
return content.flatMap(it -> ReactivePageableExecutionUtils.getPage(it, pageable, fetchCount()));
}

View File

@@ -400,6 +400,7 @@ public class ReactiveQuerydslMongoPredicateExecutorTests {
.as(StepVerifier::create) //
.assertNext(it -> {
assertThat(it.getContent().size()).isEqualTo(1);
assertThat(it.getTotalElements()).isEqualTo(2);
assertThat(it.getContent()).contains(dave);
}).verifyComplete();
@@ -409,6 +410,7 @@ public class ReactiveQuerydslMongoPredicateExecutorTests {
.as(StepVerifier::create) //
.assertNext(it -> {
assertThat(it.getContent().size()).isEqualTo(1);
assertThat(it.getTotalElements()).isEqualTo(2);
assertThat(it.getContent()).contains(oliver);
}).verifyComplete();