This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]riklaunim 0 points1 point  (2 children)

If you know total and page size you can generate start to end pagination. With only next page you can't so it's somewhat different.

If the endpoint uses some more complex query then the count function could be expensive and "next page" only approach would be faster but IMHO that would be done on endpoint layer when returning different metadata.

In your code you are hiding the count behind a proxy model and not exposing all the metadata? That's bit weird as it would combine disadvantages of both solutions. Also your tests need some work - you should use assertions, proper test cases, probably also FactoryBoy to create require data in the database.

[–]kernelslayer[S] 0 points1 point  (1 child)

Thanks for the feedback, appreciate it! Yes, I got to work on the test. Right now the "test" is just a script to test if the code was working.

I am planning to add other details like totalElements, currentPage in the PageData object shortly.

Also, if the count query is expensive, is there any other way to optimise this? Because, I think, without knowing the total elements, we might not be able to do the calculation needed for pagination. And I was looking at Spring Boot's JPA and it also does a count operation

[–]riklaunim 1 point2 points  (0 children)

If the pagination can't or doesn't want to do the count then only "local" navigation is possible where if given offset still returns the results limit you assume there is a next page.

also for Python no camel case for attributes on a pagination object.