CBLReplication pull status updates when pushing

28 views
Skip to first unread message

Brendan Duddridge

unread,
Jan 21, 2016, 5:23:02 PM1/21/16
to Couchbase Mobile
Hi,

So I've finally managed to get around to testing out Couchbase with Cloudant. So far it's working great!

But I've got a question about statuses. When I make a change and the push replicator gets called, I'm also noticing that the pull replicator is also getting called and the status is coming into the notification with a value of kCBLReplicationIdle. That would be fine if it were pulling data that was pushed from another device, but it seems to get triggered on the same device that's doing the pushing.

The reason this is a problem for me right now is because when I receive a pull from the replicator, I refresh the screen to display the new data. So this can be problematic when I'm entering data and tabbing to different fields. I lose focus from the refresh. The pull doesn't seem to be needed in this case though.

I tested to see what states a real pull goes through and basically it just goes from active to idle, which seems correct. The one that comes in when doing a push is just the idle state.

I'm just not sure if maybe I'm doing something wrong or thinking about it incorrectly.

Any pointers would be greatly appreciated. 

Thanks!

Brendan

Jens Alfke

unread,
Jan 21, 2016, 5:31:26 PM1/21/16
to mobile-c...@googlegroups.com

> On Jan 21, 2016, at 2:23 PM, Brendan Duddridge <bren...@gmail.com> wrote:
>
> But I've got a question about statuses. When I make a change and the push replicator gets called, I'm also noticing that the pull replicator is also getting called and the status is coming into the notification with a value of kCBLReplicationIdle.

What exactly do you mean by “getting called” here?

There’s always a bit of feedback when doing a push — when the server adds the pushed documents, its changes feed will wake up and send the client a notification of those documents. The client just sees that it already has those docs/revisions, so it doesn’t download them. But that may cause the puller to change its status from Idle to Busy for an instant.

> The reason this is a problem for me right now is because when I receive a pull from the replicator, I refresh the screen to display the new data.

Generally you shouldn’t use replication notifications to drive refresh of the UI. Instead, use database/document change notifications.

For example, if you’re displaying data from a document on the current screen, register a CBLDocumentChangeNotification on that document while it’s visible, and update your display when notified. This is a general “reactive” programming practice that ensures your UI is up to date with the data, no matter how the data got changed.

—Jens

Brendan Duddridge

unread,
Jan 21, 2016, 6:14:08 PM1/21/16
to Couchbase Mobile
Hi Jens,

Ah ok. That's a great idea. I have something like that already for updating the NSNetService TXT record for peer-to-peer syncing. Not sure why I didn't also use it to update the UI. I'll do that now.

Thanks!

Brendan Duddridge

unread,
Jan 21, 2016, 9:42:39 PM1/21/16
to Couchbase Mobile
Reporting back here. Worked like a charm!

Thanks Jens!
Reply all
Reply to author
Forward
0 new messages