Paging
From CS462
I'll try to briefly explain how we're doing paging in the projects.
Let's use the WebServer interface's /list/recent as a concrete example. Since we're not using a Relational-Database, we are basically creating uuids for each image. While this gives us the nice property of unique handles (and no collisions) it does not give us a nice sequential ordering of the images in the order they came in.
We have to use some other attribute other than the uuid to maintain the sequential order. For all our lab projects we're using a date/time of the submission to give a natural order to the collections, where this date/time is for all intents and purposes unique (in our scenario :) ).
One of the ramifications of using a distributed data store like SimpleDB that we'll learn later, is that the data store doesn't automatically or easily track the number of items that match a given query. We can however, ask for the first n items of a query. Since this collection is ordered by a unique timestamp, we can jump in the middle of this collection by asking for the first 10 items older than a specific time.
So how does one paginate the results without knowing how many items are in the collection?
We don't necessarily need to know how many pages there are, but we do need to know if there is at least another page.
The trick we're using is this: if we are displaying n items of collection on a page, instead of querying for the most recent n items, we query for the most recent n+1 items. If there is a n+1th item, we know we have at least one more page (in the worst case, that the n+1th item will be the only item on that page, but there is still a page). We return the first n items, then give the unique identifier of the nth+1 item, so we know where to begin the query for the next page.
In the /list/recent case, the collection is sorted by the submitdate attribute -- and the submitdate of the nth+1 element that starts the next page is returned as the 'nextsubmitdate'
