Skip to content

Allow sorting of unpaged resultsΒ #2691

@naihil

Description

@naihil

QuerydslPredicateExecutor provides a method Page<T> findAll(Predicate predicate, Pageable pageable);
You can pass Pageable.unpaged() to get all rows in single page, in this case result not sorted.
If you write custom implementation of unpaged() that has some sort and pass it to findAll, this doesnt work because of this code:
https://github.com/spring-projects/spring-data-jpa/blob/main/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/Querydsl.java#L117
`

	if (pageable.isUnpaged()) {
		return query;
	}

	query.offset(pageable.getOffset());
	query.limit(pageable.getPageSize());

	return applySorting(pageable.getSort(), query);

`
Sorting applied after isUnpaged() check.

We can change code to:
`

	if (pageable.isPaged()) {
		query.offset(pageable.getOffset());
		query.limit(pageable.getPageSize());
	}

	return applySorting(pageable.getSort(), query);

`
And this code allows sorting of unpaged queries.
Linked with #3761

Metadata

Metadata

Assignees

Labels

status: declinedA suggestion or change that we don't feel we should currently apply

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions