Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The total count for page links do not considered the complete query #41500

Closed
j1myx opened this issue Jun 27, 2024 · 2 comments · Fixed by #42202
Closed

The total count for page links do not considered the complete query #41500

j1myx opened this issue Jun 27, 2024 · 2 comments · Fixed by #42202
Labels
area/panache kind/bug Something isn't working
Milestone

Comments

@j1myx
Copy link
Contributor

j1myx commented Jun 27, 2024

Describe the bug

I'm using the quarkus-hibernate-orm-rest-data-panache extension to generate CRUD's, and in the endpoint that lists the records, the pagination links are not correct. This only becomes evident when I use a filter and/or custom query. Reviewing the source code of the rest-data-panache extension I discovered the reason:

ResultHandle pageCount = tryBlock.invokeVirtualMethod(
                    ofMethod(resourceMetadata.getResourceClass(), Constants.PAGE_COUNT_METHOD_PREFIX + RESOURCE_METHOD_NAME,
                            int.class, Page.class),
                    resource, page);

Class: io.quarkus.rest.data.panache.deployment.methods.ListMethodImplementor.java
Line: 232
Version: 3.11.2

The reason is that this SQL query to obtain the total number of records must also consider the filters and/or custom queries that I apply as part of my query-params, and in this way both queries (for the total and list) will be affected by the filters and/or queries:

return creator.invokeVirtualMethod(
        ofMethod(resourceMetadata.getResourceClass(), "list", isNotReactivePanache() ? List.class : Uni.class,
                Page.class, Sort.class, String.class, Map.class),
        resource, page == null ? creator.loadNull() : page, sort, query, dataParams);

Class: io.quarkus.rest.data.panache.deployment.methods.ListMethodImplementor.java
Line: 361
Version: 3.11.2

In this second source code fragment you can see that the query and dataParams parameters are being injected, both parameters should also be used to obtain the total.

Expected behavior

Records in my database:

id name createdBy
1 Jimy Nikola
2 Jaime Steve
3 Julio Nikola

Scenery 1:

Endpoint consumption without filtering parameters:
https://api.jimyx,dev/users?size=2

Headers obtained:
Link: https://api.jimyx,dev/users?page=0&size=2; rel="first"
Link: https://api.jimyx,dev/users?page=1&size=2; rel="last"
Link: https://api.jimyx,dev/users?page=1&size=2; rel="next"

Scenery 2:

Endpoint consumption with filtering parameters:
https://api.jimyx,dev/users?size=2&createdBy=Nikola

Headers obtained:
Link: https://api.jimyx,dev/users?page=0&size=2; rel="first"
Link: https://api.jimyx,dev/users?page=0&size=2; rel="last"

Actual behavior

Records in my database:

id name createdBy
1 Jimy Nikola
2 Jaime Steve
3 Julio Nikola

Scenery 1:

Endpoint consumption without filtering parameters:
https://api.jimyx,dev/users?size=2

Headers obtained:
Link: https://api.jimyx,dev/users?page=0&size=2; rel="first"
Link: https://api.jimyx,dev/users?page=1&size=2; rel="last"
Link: https://api.jimyx,dev/users?page=1&size=2; rel="next"

Scenery 2:

Endpoint consumption with filtering parameters:
https://api.jimyx,dev/users?size=2&createdBy=Nikola

Headers obtained:
Link: https://api.jimyx,dev/users?page=0&size=2; rel="first"
Link: https://api.jimyx,dev/users?page=1&size=2; rel="last"
Link: https://api.jimyx,dev/users?page=1&size=2; rel="next"

How to Reproduce?

No response

Output of uname -a or ver

No response

Output of java -version

No response

Quarkus version or git rev

No response

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

@j1myx j1myx added the kind/bug Something isn't working label Jun 27, 2024
@gsmet
Copy link
Member

gsmet commented Jun 27, 2024

@j1myx looks like you did all the work :). Would you be interested in providing a patch with a test?

@j1myx
Copy link
Contributor Author

j1myx commented Jun 30, 2024

Hi @gsmet, ok. I will do it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/panache kind/bug Something isn't working
Projects
None yet
3 participants