Reputation:
I would like to do a progress bar for the time when the database synchronize. The request which counts the number of documents to synchronize is too long. I tried with the request GET _active_tasks on the couchdb database but it returns an empty json. I tried with the change event of the Pouchdb function replicate but the info variable doesn't display. Have you others technics for the progress bar or would you know how used the technics I have ever tried ?
Upvotes: 0
Views: 389
Reputation: 11
I have not found a perfect solution, but one that seemed 'good enough' for us has been
get info about source db, to know what the 'end goal' is.
Add a 'changes' callback (like you mentioned in your answer), where you receive an info object with the last_seq that has been replicated. Divide this with the update_seq you got from the source, and update your progress bar.
~
Q.all(source.info())
.then(function(sourceInfo) {
var replication = source.replicate.to(target);
var startingpoint;
replication.on('change', function(info) {
// the first time we get a replication change,
// take the last_seq as starting point for the replication
// and calc fractions based on that
var fraction = 0;
if(typeof startingpoint === "undefined") {
startingpoint = info.last_seq;
} else {
fraction = (info.last_seq - startingpoint) / (sourceInfo.update_seq - startingpoint);
}
// Whatever you need to do to update ui here
updateUi(fraction);
});
})
Upvotes: 1