From 38575baec1a703d123e9912da77cddbba068d634 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Thu, 8 Feb 2018 10:03:30 +0100 Subject: [PATCH] DATAMONGO-1860 - Retrieve result count via QuerydslMongoPredicateExecutor only for paging. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We now use AbstractMongodbQuery.fetch() instead of AbstractMongodbQuery.fetchResults() to execute MongoDB queries. fetchResults() executes a find(…) and a count(…) query. Retrieving the record count is an expensive operation in MongoDB and the count is not always required. For regular find(…) method, the count is ignored, for paging the count(…) is only required in certain result/request scenarios. Original Pull Request: #529 --- .../support/QuerydslMongoPredicateExecutor.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/QuerydslMongoPredicateExecutor.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/QuerydslMongoPredicateExecutor.java index 4e3a7608d..c84f2fef8 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/QuerydslMongoPredicateExecutor.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/QuerydslMongoPredicateExecutor.java @@ -115,7 +115,7 @@ public class QuerydslMongoPredicateExecutor implements QuerydslPredicateExecu Assert.notNull(predicate, "Predicate must not be null!"); - return createQueryFor(predicate).fetchResults().getResults(); + return createQueryFor(predicate).fetch(); } /* @@ -128,7 +128,7 @@ public class QuerydslMongoPredicateExecutor implements QuerydslPredicateExecu Assert.notNull(predicate, "Predicate must not be null!"); Assert.notNull(orders, "Order specifiers must not be null!"); - return createQueryFor(predicate).orderBy(orders).fetchResults().getResults(); + return createQueryFor(predicate).orderBy(orders).fetch(); } /* @@ -141,7 +141,7 @@ public class QuerydslMongoPredicateExecutor implements QuerydslPredicateExecu Assert.notNull(predicate, "Predicate must not be null!"); Assert.notNull(sort, "Sort must not be null!"); - return applySorting(createQueryFor(predicate), sort).fetchResults().getResults(); + return applySorting(createQueryFor(predicate), sort).fetch(); } /* @@ -153,7 +153,7 @@ public class QuerydslMongoPredicateExecutor implements QuerydslPredicateExecu Assert.notNull(orders, "Order specifiers must not be null!"); - return createQuery().orderBy(orders).fetchResults().getResults(); + return createQuery().orderBy(orders).fetch(); } /* @@ -168,8 +168,7 @@ public class QuerydslMongoPredicateExecutor implements QuerydslPredicateExecu AbstractMongodbQuery> query = createQueryFor(predicate); - return PageableExecutionUtils.getPage(applyPagination(query, pageable).fetchResults().getResults(), pageable, - () -> createQueryFor(predicate).fetchCount()); + return PageableExecutionUtils.getPage(applyPagination(query, pageable).fetch(), pageable, query::fetchCount); } /*