Skip to content

Commit ddee2fb

Browse files
committed
DATAMONGO-1057 - Polishing.
Slightly tweaked the changes in SlicedExecution to simplify the implementation. We now apply the given pageable but tweak the limit the query uses to peek into the next page. Original pull request: #226.
1 parent 6512c2c commit ddee2fb

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/AbstractMongoQuery.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,10 @@ Object execute(Query query) {
233233
MongoEntityMetadata<?> metadata = method.getEntityInformation();
234234
int pageSize = pageable.getPageSize();
235235

236-
List result = operations.find(query.skip(pageable.getOffset()).limit(pageSize + 1).with(pageable.getSort()),
237-
metadata.getJavaType(), metadata.getCollectionName());
236+
// Apply Pageable but tweak limit to peek into next page
237+
Query modifiedQuery = query.with(pageable).limit(pageSize + 1);
238+
239+
List result = operations.find(modifiedQuery, metadata.getJavaType(), metadata.getCollectionName());
238240

239241
boolean hasNext = result.size() > pageSize;
240242

0 commit comments

Comments
 (0)