Get private document on demand

In our application users can receive a number of private messages. Each message is tagged by “user-{uid}-messages” channel so we can replicate them in user {uid} context. But pulling all user’s messages with their bodies is quite expensive and to save time and mobile data usage we split message into two documents - “message_header” and “message_body”. We pull all message headers tagged with user channel to show the list of messages and pull body only when it requested (message is opened by the user). To do so we tag message_body with “message-{mid}” channel and grant user access to each one. This approach is working fine but leads to a huge number of channels user has access to.

Is it a correct way to go and won’t it be a problem when user has a lot of channels?

Performance will degrade when pulling from very large numbers of channels.

It would be better to tell the replicator to pull the individual document … except that Sync Gateway hasn’t implemented its side of that functionality. Any plans to implement that, @adamf?

No, there will be only one channel pull a time - first from user channel to get all his message headers, next when user open the message we pull only from this message channel to get the body.

But in this case we have to give user access to each message channel, so thousands users will have thousands channels and I wonder if it’ll be a problem.

Yes, perfect solution will be to pull individual documents but only those user has access to through channels.