i was wondering if adding multiple channels to my sync gateway could affect the amount of data passed to a CBLite in android.
Suppose that i have 3 channel, and 3 activities which used data coming from those channels. The data in my CouchBase server do not change very often, but i want to have a real time update, so i set the pull replication to continuous. Seen that the data not change very often, and the activities use only one channel a time, i though to set replication’s channel each time an activity has started(for example in onResume i call setChannels(channel) switching the channel of my singleton database class).
Do you think is worth it to switch channels or i just could subscribe to all my channel and do not bother about the data that could be pulled even if it has not been used by the current activity?
I’ve got also a type of data that i use in my entire application that probably will never change, and i would’t use a continuous replication, and i was wondering how could i sent something like a notification when that type of data change instead to a continuous pulling.
I would recommend fetching all the data that the app/user is authorized to and for each activity to use Query (or LiveQueries) to filter on the data that is applicable for the activity.
Few reasons why you may want to design it this way -
Channels are meant to facilitate user-level granularity of data routing and authorization. You would not want to tie in your app workflow logic to channels because if your app activities change (which is very realistic in a real world app) as your app evolves , it wouldn’t be practical to change your sync gateway (which would need to serve older versions of the apps and also what if you have iOS apps with completely different views)
If your app is used in offline mode before all the activities have synced across all the channels, you will potentially run into the issue of having inconsistent data across the activities which may be undesirable
Trying to sync data at the time when activity is resumed is an anti-pattern to building a responsive app. In other words, one of the goals of doing the continuous replication in the background is to ensure that when your activity is launched, it has more or less the latest snapshot of data. If you are pulling from channels overtime you launch the activity, it isn’t very different that doing an on-demand pull of data
You could start with a pre-built database that’s bundled with your app if it “never changes”.
But if it is semi-static, you can set one-shot replication mode. You can use Google’s push replication service to notify your app of changes and then do a one-shot replication pull the data. Alternatively , if the changes are not desired in real time, you can trivially do a one-shot replication every time the app is launched to sync any possible changes.
Another way is that you can write a special document onto a channel that is anyway being continuously replicated which would be like a trigger for the app to pull the other data.
If real time update of semi-static data is a need, note that there isn’t much of an overhead (like data bandwidth usage, battery usage ) keeping the replication open in continuous mode. The main idea of continuous mode is that its hassle free for the app developer.