I’m developing an app where user can do numerous updates to the same data within a short period of time. On top of that, I would like to reduce syncing for not premium users to once per day. My motivation is to reduce the number of requests to the server.
Similar topics were raised already in this forum:
How can I avoid syncing on every commit?
How to optimize Realm Sync for performance
and the only solution suggested was to handle that manually and put data into synced realm once a while.
In my case that adds a lot of complexity to my code. And it seems it should be easily avoided if I would pause the sync and resume it once in a some period, then pause again.
I have done my experiments already and here is what I got (I’m using React Native).
Option 1. This is just for upload, but I suppose it can be coupled with download callback. It has a drawback though – resume does not happen instantly – it waits for the next change in realm:
realm?.syncSession?.resume();
realm?.syncSession?.addProgressNotification(
'upload',
'forCurrentlyOutstandingWork',
(transferred, transferable) => {
if (transferred >= transferable) {
realm?.syncSession?.pause();
}
}
);
Option 2. This also has a drawback – requests to the server are sent even when there were no local changes:
realm?.syncSession?.resume();
realm?.syncSession?.uploadAllLocalChanges().then(() => {
console.log('pausing transferring (fulfilled)');
realm?.syncSession?.pause();
}, (reason) => {
console.log(`pausing transferring (rejected: ${reason})`);
realm?.syncSession?.pause();
});
Please advice and share your ideas. Do you know of any plans to support this “delayed” sync out of the box?