DATAMONGO-1860 - Retrieve result count via QuerydslMongoPredicateExecutor only for paging.
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
This commit is contained in:
committed by
Christoph Strobl
parent
f1a3c37a79
commit
38575baec1
@@ -115,7 +115,7 @@ public class QuerydslMongoPredicateExecutor<T> implements QuerydslPredicateExecu
|
|||||||
|
|
||||||
Assert.notNull(predicate, "Predicate must not be null!");
|
Assert.notNull(predicate, "Predicate must not be null!");
|
||||||
|
|
||||||
return createQueryFor(predicate).fetchResults().getResults();
|
return createQueryFor(predicate).fetch();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -128,7 +128,7 @@ public class QuerydslMongoPredicateExecutor<T> implements QuerydslPredicateExecu
|
|||||||
Assert.notNull(predicate, "Predicate must not be null!");
|
Assert.notNull(predicate, "Predicate must not be null!");
|
||||||
Assert.notNull(orders, "Order specifiers 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<T> implements QuerydslPredicateExecu
|
|||||||
Assert.notNull(predicate, "Predicate must not be null!");
|
Assert.notNull(predicate, "Predicate must not be null!");
|
||||||
Assert.notNull(sort, "Sort 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<T> implements QuerydslPredicateExecu
|
|||||||
|
|
||||||
Assert.notNull(orders, "Order specifiers must not be null!");
|
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<T> implements QuerydslPredicateExecu
|
|||||||
|
|
||||||
AbstractMongodbQuery<T, SpringDataMongodbQuery<T>> query = createQueryFor(predicate);
|
AbstractMongodbQuery<T, SpringDataMongodbQuery<T>> query = createQueryFor(predicate);
|
||||||
|
|
||||||
return PageableExecutionUtils.getPage(applyPagination(query, pageable).fetchResults().getResults(), pageable,
|
return PageableExecutionUtils.getPage(applyPagination(query, pageable).fetch(), pageable, query::fetchCount);
|
||||||
() -> createQueryFor(predicate).fetchCount());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user