spring-data-couchbase icon indicating copy to clipboard operation
spring-data-couchbase copied to clipboard

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

Open aaronjwhiteside opened this issue 5 years ago • 1 comments

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();

aaronjwhiteside avatar Jan 21 '21 03:01 aaronjwhiteside

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

mikereiche avatar Mar 24 '21 21:03 mikereiche