How to get the replication progress?

Hi. I’m trying to show the replication progress to the user, but so far I can’t find a way to retrieve this information. I am using iOS. I know about the changesCount and completedChangesCount from the replication object, but you can’t easily convert this to percentage progress as the changesCount keeps going while replication is running. Any idea what could be done about this?

Docs for changesCount:

Hi @roundandround,

Yes the changesCount may change during the replication because the total number of changes to be pulled a not known ahead of time.

This answer from another thread on the google groups has some good info too

The puller doesn’t know how many docs it’s going to pull until it reaches EOF on the changes feed. On the other hand, if it reads the feed as fast as possible, it has to buffer all the doc/revision IDs in memory because the actual download process can’t keep up. That turned out to cause problems with large downloads. So now the feed is throttled so it doesn’t get too far ahead of the downloading … but that means the puller doesn’t know how many documents there are until fairly late in the process.

Another possibility would be to ask the server how many documents are in the feed before reading the feed. Unfortunately that would require Sync Gateway to do a lot of redundant work, and the task of generating that feed is already pretty expensive (and complex) on the server side, so I don’t think that’s feasible.

I hope this helps to answer your question about why changesCount keeps going up during a replication. I’m not sure what’s the best practice to recommend.

If you want to use it anyways, this tutorial might have some helpful info but it looks like you already figured it out.

Otherwise, you might use the Replication.status property to display the Stopped, In progress and Completed icons instead of a progress bar.