Best practices for populating CBL


I have a cordova app where if a user is re-installing the app and it’s doing a pull sync with sync-gateway, the number of documents could be large, like over a 1000. What are the best practices for populating CBL through sync-gateway?

Should I do a “GET /{db}/_all_docs” or “GET /{db}/_changes”?

Use a pull replication.

If you start talking to the server directly, you’re basically trying to re-implement the replicator. Even for a special case like populating an empty database, that’s going to be difficult.

If you’re finding the replicator too slow, then let’s investigate that. What version/platform of CBL, and what device(s)? Obviously there are a lot of variables, but I can say that, given enough network bandwidth and disk speed, the iOS version can pull about 2000 docs per second. Real world performance may not match that, due to the limitations of cell networks and cheap flash storage, but any replication code you write will be subject to those same limitations.


Is there a way to find out how many documents will need to be loaded in the initial replication? I want to display a spinner during the initial sync.

GET /_active_tasks will return info about active replications including the expected number of changes. However this value changes during replication as more entries are read from the server’s changes feed; it takes a while to stabilize to the actual number.

Awesome. Thanks @jens!