Retrieving documents from intersection of channels

50 wyświetleń
Przejdź do pierwszej nieodczytanej wiadomości

Matthew Singer

nieprzeczytany,
5 maj 2015, 17:14:325.05.2015
do mobile-c...@googlegroups.com
I am using Couchbase Lite .NET running on Xamarin.Android to retrieve documents from a server with the user's name in the channels list:

{
  "_id": "normalDoc",
  ... some data here...
  "channels": [
    "user1"
  ]
}

This works just fine. What I'd like to do is create a "priority" channel specifically for documents I want to retrieve ASAP:


{
  "_id": "priorityDoc",
  ... some data here...
  "channels": [
    "user1",
    "priority"
  ]
}

I specifically do not want to give the user access to the entire "priority" channel because I only want them to see ones assigned to them. I figured I could retrieve this through a one-shot replication that runs immediately:

Replication _priorityReplication = _database.CreatePullReplication(uri);
_priorityReplication.Channels = new List<string> { "priority" };
_priorityReplication.Start();

This replication does not pull anything. If I add the user to the channel list, then it pulls everything for that user, priority or not.

My hope was that with only the "priority" channel, the sync gateway would sync the intersection of the two channels, everything in "priority" that the user has access to from their own channel as well. I would prefer not to create filters that need to be re-created every time I re-deploy the server, and I would also prefer to use as few magic channel names as possible, for simplicity's sake. Am I mistaken about how Replications and the Sync Gateway handle channels, and am I out of luck regarding filters/magic-named channels

Jens Alfke

nieprzeczytany,
5 maj 2015, 19:30:275.05.2015
do mobile-c...@googlegroups.com

On May 5, 2015, at 2:07 PM, Matthew Singer <matt.s...@gmail.com> wrote:

My hope was that with only the "priority" channel, the sync gateway would sync the intersection of the two channels, everything in "priority" that the user has access to from their own channel as well.

No. When you specify multiple channels you're asking for their union. Since the user doesn't have access to any documents in the "priority" channel, asking for it is a no-op.

—Jens

Matthew Singer

nieprzeczytany,
6 maj 2015, 10:03:476.05.2015
do mobile-c...@googlegroups.com
Gotcha, thanks for the quick response.

Janaka Jayasuriya

nieprzeczytany,
25 lut 2016, 01:53:0725.02.2016
do Couchbase Mobile
No. When you specify multiple channels you're asking for their union. Since the user doesn't have access to any documents in the "priority" channel, asking for it is a no-op.

—Jens

Hi Jens, is it possible to get the intersection? 

Jens Alfke

nieprzeczytany,
25 lut 2016, 12:54:0625.02.2016
do mobile-c...@googlegroups.com
Not with the current implementation. You can file an issue to request this, but my guess is that it wouldn’t be easy to add, probably requiring significant internal rework of the way changes feeds are generated.

However, note that your sync function is solely in charge of which channels a doc is added to. So you can add some logic to it that adds the doc to a special ‘union’ channel if it’s being added to all the relevant channels.
if (a) channel(“a”);
if (b) channel(“b”);
if (c) channel(“c”);
if (a && b && c) channel(“a-b-c”);
Then the client can request to pull channel “a-b-c”.

—Jens

Janaka Jayasuriya

nieprzeczytany,
25 lut 2016, 23:59:5325.02.2016
do Couchbase Mobile
Hi Jens, thanks for responding and for the sync function example, will try it out.
Odpowiedz wszystkim
Odpowiedz autorowi
Przekaż
Nowe wiadomości: 0