I've just started using Dexie, I especially want to make use of it's syncing capabilities.
I have implemented a basic sync protocol, and I'm fairly happy that it can fetch data and keep things up to date across clients and the server.
The one big issue I have is trying to figure out *when* Dexie wants to initiate syncing.
My simplest use-case is to sync user settings/preferences between clients. To this end, I've set up a 'usersettings' schema, and implemented a protocol, finally calling db.syncable.connect() with appropriate arguments. Unfortunately, I am unable to share any specific code with you.
If I clear out the browser's databases, and load my app (like a user would for the first time) - Dexie happily creates everything, syncs, and writes data into the database.
The issues start when I reload the page. As far as I understand, before calling db.syncable.connect() I do need to know the db.syncable.getStatus() for the url. In my case, I am only calling db.syncable.connect() if the status is -1 or 0. In other cases, I believe Dexie knows the syncer exists and should start the polling.
Most of the time, Dexie never starts polling.
I've dug through the code, and established (via adding copious amounts of logging), that Dexie.Observable has an internal polling loop which repeatedly calls cleanup(). At some point, on some client, it should establish whether that client becomes the sync master, and the cleanup handler in Dexie.Syncable will then initiate the db.syncable.connect() call. I understand why this is done - we only need one active client to perform the syncing.
What I have observed though, is that even with a database which has only ever had one client connect (i.e. start from empty database, load, then reload in the same tab) - the Dexie.Observable cleanup() polling never decides that this tab is the master, and hence no syncing ever starts.
Other times, if I do have 2 tabs open, one of them will eventually claim to be master and start the syncing - however the time interval to reach this decision far exceeds any of the sync protocols' intervals. It can take minutes for any syncing to happen.
Am I maybe doing something wrong? Anyone else seen this behaviour?
I'm developing against Firefox 38.4.0 on Centos 6.6.
Regards,
Doug Hammond
Thanks David, it's nice to know I wasn't completely off the mark.
What I've ended up doing is to ditch Dexie.Syncable and write a simpler syncer implementation which can call into the same ISyncProtocol interface.
I also did a little work with observing the 'cleanup' event and now get an instant notification in all tabs when the master changes. With the help of 2 extra booleans, I can reliably fire an event to let the system know if it should start or stop the syncs.
In my world I store no state about the syncer, but let the Observable master/slave state change do what you would call the 'connect'.
One other quirk I noticed which didn't appear to be documented was that Observable will not fire change events on tables which start with underscore (e.g. '_syncerdata') ? That took a while to figure out.
Cheers,
Doug.
Hi,
Unfortunately my code is part of a proprietary application used internally by the company I work for, so I won't be able to share any code. I haven't made any modifications to Dexie itself either.
Regards,
Doug