As you have gathered, the Pagination object in OGM, which supports the Spring Page object, does not use the page counter or returns it. Spring The page object provides a method for returning the total number of pages, but this requires a basic implementation โ Mongo, JPA, Neo4j, etc. Spring Page object uses this value to determine the presence or absence of the "next" page. Our implementation "tricks" by telling Spring what it always does, until a request for a new page gets fewer results per page.
Unfortunately, there is no generalized way to return the number of pages that does not involve first finding all the results, and then counting them. Doing this for user queries that can potentially return many thousands of rows gives the obvious risk of running out of heap space on the server. (Note that the basic implementation in Neo4j using SKIP and LIMIT does not require preloading all the results into memory, so it does not encounter this problem).
Vince
source share