How to deal with large lists in Chaplin / PouchDB?

31 views
Skip to first unread message

Bernd

unread,
Jul 26, 2013, 4:38:34 AM7/26/13
to chapl...@googlegroups.com
I set up a Chaplin application relying on a PouchDB (synced via BackbonePouch Adapter). The application is intended to be an offline application running via Phonegap on IOS and maybe later Android.

In my database model I use a map/reduce query that returns a large record set (> 4.000).
My actual setup would pass this large collection to the Chaplin/Backbone collection. Once instantiating a view it would render all records at one time, which makes the browser of course incredibly slow.

My question is now, what is the best way to reduce the result set for the view (there is no need for me to show all records at one time)?

I would see two major approaches.

1st: Within the database: Let the database return only a subset of records and head this over to the collection and the view.

2nd: Within a Backbone / Chaplin collection: In this scenario I would load all records to the collection and generate a subset within the controller, respectively the view.

The advantage of the 2nd solution is, that I don't have to care about syncing. Any time I do a change on one of the records the Sync Gateway of BackbonePouch ensures that the underlying record in the database is persistent. In the first solution I have to write update methods that pass changes via put, remove functions of the database.

There are still questions for me for both scenarios:

1. In PouchDB queries I can use a "limit" parameter to reduce the result set. As there is no offset parameter as in CouchDB, I do not know how to receive the next result sets, that have not been sent within the first call. (e.g.: If the result set is let's say 100 records, I can set "Limit: 20" and would get the first 20 records, but I have no idea how to get the next 20 records)

2. In Chaplin / Backbone Collections I would probably use the Controller to reduce a result set. Is this the correct way?

Are there any good code examples to study?

I appreciate any hint.

Thank you very much in advance.
Reply all
Reply to author
Forward
0 new messages