spring-projects / spring-data-rest

Simplifies building hypermedia-driven REST web services on top of Spring Data repositories
https://spring.io/projects/spring-data-rest
Apache License 2.0
921 stars 562 forks source link

Feature Request: Option to Disable Total Count in Spring Data REST for Improved Performance (or use Slice interface) #2426

Open cjullien opened 3 weeks ago

cjullien commented 3 weeks ago

I’d like to request a new feature that allows disabling the total count (count) in Spring Data REST endpoints. In some scenarios, especially with large datasets, counting all entities for pagination can lead to significant performance issues. Therefore, I believe it would be beneficial to have a configurable option to bypass the count query when it’s not essential for the client application.

Suggested Feature Add a configuration option in Spring Data REST to:

Disable the total count in all paginated responses or use the Slice interface instead of Page for default find. Optionally control the count per query/request: Allow overriding the count calculation on a per-request basis by setting a query parameter or using an annotation on repository methods.

Use Case

In cases where only the data of the current page is necessary (without the need for total elements) or with many data in bdd, the count query adds overhead. Disabling it could significantly improve response times for paginated endpoints working with large datasets.