Support Slice in the PagedResourcesAssembler [DATACMNS-845]
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
Sliceinstead of aPage. But thePagedResourcesAssemblerdoes not allow to convert aSliceto aResource. It would be great to add atoResource(Slice<T> entity)method, or even addSlicedResourcesAssemblerclass.
Reference URL: https://github.com/spring-projects/spring-hateoas/issues/443
2 votes, 4 watchers
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
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.
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.
You're right, will look into it :+1:
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: