spring-data-commons icon indicating copy to clipboard operation
spring-data-commons copied to clipboard

Support Slice in the PagedResourcesAssembler [DATACMNS-845]

Open spring-projects-issues opened this issue 9 years ago • 5 comments

Oliver Drotbohm opened DATACMNS-845 and commented

From the original ticket in Spring HATEOAS:

Sometimes we cannot have information such as the total elements and total pages of a request, that's where we're using a Slice instead of a Page. But the PagedResourcesAssembler does not allow to convert a Slice to a Resource. It would be great to add a toResource(Slice<T> entity) method, or even add SlicedResourcesAssembler class.


Reference URL: https://github.com/spring-projects/spring-hateoas/issues/443

2 votes, 4 watchers

spring-projects-issues avatar Apr 12 '16 09:04 spring-projects-issues

Hi Oliver, I've seen that the parent issue of this one is closed and this one has remained open for a while, last update being end of last year after nearly 4 years. I wonder if this has any chance to get into HATEOAS because I am returning pages of a large set of entities and it's becoming a heavy operation over time; a possible improvement would be to return slice... But as we are using HATEOAS we are a bit tied to pages because clients are consuming the hypermedia. Have checked some of the last release notes and have not seen anything about Slice support: is this still being considered a candidate for your backlog? Thanks. /Alberto

asjp1970 avatar Feb 07 '21 00:02 asjp1970

Same issue here: we are exposing a MongoDB collection with 1M+ elements via Spring HATEOAS and Page has become utterly inefficient due to the -useless in this case- total page number called through a count(). A Slice support would perhaps mitigate this huge performance bottleneck.

bigjoe-memooria avatar Feb 11 '21 14:02 bigjoe-memooria

As a workaround it should be possible to issue repository methods returning a Slice and adding navigation links pointing to the previous and potentially next slice manually. Wouldn't mind to see such code wrapped into a SliceRepresentationModelAssembler effectively producing a CollectionModel<T> with the aforementioned links added in a pull request.

odrotbohm avatar Feb 11 '21 15:02 odrotbohm

You're right, will look into it :+1:

bigjoe-memooria avatar Feb 12 '21 11:02 bigjoe-memooria

This bothered me enough I took a stab at solving it. Added SlicedModel to spring-hateoas and added SlicedResourcesAssembler plus injection to spring-data-commons. The HATEOAS MR needs to get merged first as the resources assembler needs that to be present in hateoas. Hopefully I did everything correctly :crossed_fingers:

mschout avatar Oct 04 '22 22:10 mschout