How to disable count request from PageRequest to get summary pages?

We use Spring data with PageRequest and fall into a much larger data set. All queries are optimally executed, except for the query being executed, to get the total number of pages. Is there a way to disable this feature, or are we likely to have to implement our own file?

http://static.springsource.org/spring-data/data-commons/docs/1.3.2.RELEASE/api/org/springframework/data/domain/PageRequest.html

http://static.springsource.org/spring-data/data-commons/docs/1.3.2.RELEASE/api/org/springframework/data/domain/Pageable.html

Edit:. After further analysis, I believe that the only way to solve this problem is not to use Spring Data and use EntityManager, since it allows you to return the initial row and the number of records. We only need the next page, so we just extract one additional entry. We also need a dynamic query that is not possible in Spring Data.

Edit 2: And it would seem I just didn't wait long enough for some answers. Thanks guys!!!

+8
source share
1 answer

The way to achieve this is to simply use List as the return value. So, for example, for a repository defined like this:

 interface CustomerRepository extends Repository<Customer, Long> { List<Customer> findByLastname(String lastname, Pageable pageable); } 

The query execution mechanism applies the offset and page size as passed to Pageable but does not start the request of the additional counter, since we do not need to create a Page instance. This is also documented in the relevant sections of the reference documentation.

Update: if you want to go to the next / previous Page but skip the counting request, you can use Slice as the return value.

+21
source

All Articles