quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.63k stars 2.64k forks source link

Spring Data Jpa - Slice return type must to avoid to trigger a count query #9357

Open arielcarrera opened 4 years ago

arielcarrera commented 4 years ago

Describe the bug When a method returns a Slice, it triggers a count query

Expected behavior When a method returns a Slice, must to avoid to trigger a count query

Actual behavior When a method returns a Slice, it triggers a count query

To Reproduce Steps to reproduce the behavior:

  1. A repository method with a Slice return type and a Pageable argument

Configuration

Screenshots

Environment (please complete the following information):

Additional context

quarkusbot commented 4 years ago

/cc @geoand

glefloch commented 3 years ago

Currently, when using a slice, we use the following constructor which require a page:

public SliceImpl(List<T> content, Pageable pageable, boolean hasNext) {

There is an other constructor of the Slice which does not require a page. If we use this one, we could avoid the count query.

WDYT @geoand ?

geoand commented 3 years ago

I don't remember TBH. If you try it and it works, by all means open a PR :)

Last time I checked (which was months ago), I didn't implement it properly because we didn't have this kind of fuctionality in Panache, so a count query was the only way to go. But if you have a solution, then go for it :)

glefloch commented 3 years ago

it looks like there is a range query now. I will give it a try and open a PR if this works :)

geoand commented 3 years ago

Cool!