We are currently building a platform for content sharing, where every user has access to a sub-set of all available documents. The access rights for each document and user can change. The number of documents is much larger than the number of users (ratio 100/1).
From my understanding, Sync Gateway offers two ways to handle this problem:
A - Every user account has its own channel and each document has a channel property which contains an array of all the channels (i.e. users) to which it belongs. The sync function then maps the document to all the listed channels.
B - Each document has its own channel and we give the users the access rights to the different document-channels through a sync function or the Admin API.
The problems with A we see are that :
- we do not want to store a channel array in each document since this is information should be hidden from the user,
- the update of the channel-array will create a new revision of the document which will trigger an unnecessary replication to all users who already have access to the document,
- there is currently no Admin API call which would allow us to assign a list of document ids to one or more channels, e.g. assign([docId1,docId2,...],[channel1,...]). This would be similar to the method 'channel([channel1,channel2,...])' which is available in the sync function.
The problem with B is that the number of documents is much larger than the number of users and we will end up with a very larger number of channels and channels per user (of course, we could bundle all the channels to which a user has access in a role per user, but this does not solve the problem). For the moment, we are not sure how this solution will scale.
Additionally, we need to treat the case where a user loses access to a document. Depending on the chosen solution, we end up with the following situation:
A - The document will be removed from a user's channel. Sync Gateway will communicate this to CBL as a new revision of the document with a deleted-property. This event can be detected on any device, such that the document can be deleted locally.
B - The user loses access to the document's channel. Currently, Sync Gateway does not trigger any event which would inform the user that the document should be deleted from its local database. One needs to handle this problem separately.
Overall, none of the two solutions seems to be optimal, although it should be a classic use-case of Sync Gateway.
Therefore, I am curious to know if there are any better solutions to our problem and/or if I am missing something important?