LiveQuery Missing Channel Changes

I have a weird issue that combines sync, live query and changing a channel.

TLDR: I have data where I change only the channel, and in certain specific circumstances, that change will not be detected by a live query.

Its a little complex - I’m going to try to make this short and clear.

I have an app that runs on mac and iOS. I used channels a lot to segment and share data.
If I have my app using the same account running on two instances (so the same set of channels), and I move a piece of data from one channel to another… everything works. The change is detected at the other end and the data disappears (if my live query is monitoring the source channel) or appears (if my live query is monitoring the destination channel). Note that by “move”, I mean changing the channels array.

However, if the two instances are using a different account so they have a different set of channels but one of those channels is shared, then the following happens:

  • if on InstanceA I move data from a non-shared channel to a shared channel, then the live query on InstanceB which is monitoring the shared channel sees that change and reacts (shows new data).
  • if on InstanceA I move data from the shared channel to a non shared channel, then the live query on InstanceB which is monitoring the shared channel does not see that change.

InstanceB should react because the live query result set changes (there is 1 less row of data). It does not.

I can see my app perform a sync - I have a “syncing” indicator and as soon as I change the data’s channel on instanceA, both instances of the app do some syncing.

I monitor the actual .cblite2 database, and I can see the row disappear from InstanceB, which is correct because it no longer exists in the channels InstanceB has access to.

This happens both ways - that is InstanceA and B react the same whether either or both are Mac/iOS.

Here is the live query instantiation. Note that the section_id is a subset or grouping of data in a channel. If I change ONLY the section_id and keep the channel the same, everything works. If I change the channel and section id, then the above error occurs. The key is to move data so that it is no longer accessible by one side (i.e. no longer a member of a channel).

    liveQuery = QueryBuilder.Select(SelectResult.Expression(Meta.ID), SelectResult.Property("section_id"), SelectResult.Expression(Meta.Sequence))
                   .From(DataSource.Database(DB.Instance.database))
                    .Where(Expression.Property("type")
                        .EqualTo(Expression.String("Notes"))
                    .And(Expression.Property("section_id")
                        .EqualTo(Expression.String(currentSectionId))));
            handlerToken = liveQuery.AddChangeListener(UpdateNotes);

I’ve been experimenting with different SelectResults to see if that helps, including SelectResult.All(). That hasn’t worked.

(Side question - can I simply do a live query and Select the ID and Sequence number. That should catch any change, right?).

Any pointers as to my mistake would be most appreciated.
Thx.
Paul.

This sounds like a known bug in live queries: they do not update after a document is purged. In your situation, when the document is removed from the channel, the replicator responds by purging the local copy of the document.

This bug is fixed in the upcoming release of Couchbase Lite. I don’t think we have a release date yet, but we’re close to finishing QA so it shouldn’t be too long.

Sorry for the slow response.

That does sound like the problem - so thanks for letting me know.
I am eagerly anticipating the next release.

Cheers.
Paul.

Couchbase Mobile 2.7 was released in Jan with this fix. Please try it out if you haven’ already done so.