spring-projects / spring-data-couchbase

Provides support to increase developer productivity in Java when using Couchbase. Uses familiar Spring concepts such as a template classes for core API usage and lightweight repository style data access.
https://spring.io/projects/spring-data-couchbase
Apache License 2.0
274 stars 190 forks source link

Support selecting and counting in parallel in SimpleCouchbaseRepository#findAll(Pageable pageable) #1061

Open aaronjwhiteside opened 3 years ago

aaronjwhiteside commented 3 years ago

We use something like this in our custom base repository:

final Mono<Long> totalCount = getReactiveCouchbaseOperations().findByQuery(getEntityInformation().getJavaType())
                    .withConsistency(buildQueryScanConsistency())
                    .matching(new Query().with(pageable))
                    .count();

final Mono<List<T>> pageContents = getReactiveCouchbaseOperations().findByQuery(getEntityInformation().getJavaType())
                    .withConsistency(buildQueryScanConsistency())
                    .matching(new Query().with(pageable))
                    .all()
                    .collectList();

// zip the two queries together to return the requested Page
return Mono.zip(pageContents, totalCount, (list, count) -> new PageImpl<T>(list, pageable, count))
                    .block();
mikereiche commented 3 years ago

Agreed. But the whole paging business needs to be revisited. Using limit and skip is not efficient. Paging should be key-based.