incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paul Carey" <>
Subject Paging
Date Fri, 10 Oct 2008 13:52:42 GMT
I just came across the following issue when paging.

Consider a database containing ten documents, each with a letter and
number, as follows:

                    a1, a2, a3, b1, b2, b3, b4, b5, c1, c2

Offset (desc false)  0,  1,  2,  3,  4,  5,  6,  7,  8,  9

Imagine a user wants to retrieve all 'b' docs, displaying 2 docs per page
We query with


and receive b1, b2 with a offset of 3. The user hits next. We issue
the query based on the data the user is currently viewing


This returns b3, b4 with an offset of 5.

The difficulty is with knowing whether to display a next / prev link.
Assume we've written our reduce function so we know that 5 'b' docs
exist. The total doc count, offset and number of docs returned isn't
enough. We also need the original offset (3 in this case). Assuming we
have that we can display a next link based on
(offset - original_offset) + count < total_docs

This approach then requires three queries per paginated page - one
each for the data, original offset and total doc count (for the key) -
and seems a little convoluted to me. Am I missing an easier approach?



View raw message