A little bit about my new program-frankenstein. Now it is an endless Paginator for Django. It sounds crazy, isn’t?
Standart Django Paginator uses the count() function for the verification of page number. It is converted to the SELECT COUNT(*) ... query, of course. But as I was explained (I really don’t know, maybe it’s just an exaggeration - you can post your opinion in the commentaries), this is not a such lightweight query, as we want for the paginated rest api, because of the MVCC in PostgreSQL.
How we can avoid the extra COUNT(*) query? Don’t panic, we can trick the Django.
First of all we need to disable count parameter from the api response. We can introduce a custom pagination serializer:
The next our move - disable the page number verification. This can be done by the custom paginator class:
Oh, goodness - we introduced the infinity number of the pages and the infinity number of elements… But we want also the correct next/prev links, so one more detail:
This solution looks very questionable, but exciting for me. If you have something to say about this - welcome! =)