Remove the sort from query before executing count. (#1194)

Also creates the query with skip and limit from any Pageable parameter instead of applying it later.
Closes #1191.
This commit is contained in:
Michael Reiche
2021-08-18 09:07:15 -07:00
committed by GitHub
parent 7e2963a365
commit dffd203a57
4 changed files with 37 additions and 14 deletions

View File

@@ -76,6 +76,7 @@ import org.springframework.data.couchbase.util.IgnoreWhen;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
@@ -449,7 +450,7 @@ public class CouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegr
Long count = airportRepository.countFancyExpression(asList("JFK"), asList("jfk"), false);
assertEquals(1, count);
Pageable pageable = PageRequest.of(0, 2);
Pageable pageable = PageRequest.of(0, 2).withSort(Sort.by("iata"));
Page<Airport> aPage = airportRepository.findAllByIataNot("JFK", pageable);
assertEquals(iatas.length - 1, aPage.getTotalElements());
assertEquals(pageable.getPageSize(), aPage.getContent().size());