ground-db icon indicating copy to clipboard operation
ground-db copied to clipboard

Local data not uploading / syncing

Open isAlmogK opened this issue 9 years ago • 18 comments

I'm seeing that my local data is not syncing back online when I go from online to offline, it just saved locally. And sometimes it's deleted before it syncs online

isAlmogK avatar May 21 '15 11:05 isAlmogK

Recreating the issue I'm doing the following

Open my app in online mode (groundDB is synced and is ok) Go offline (airplane mode on) Fill out a form which creates local collection (grounded) Check the data was saved locally Close the app (browser tab) *** I believe this is causing the issue Go online (airplane mode off) Open the app again no sync that data is not uploaded Now at some point the local data is also lost

isAlmogK avatar May 21 '15 12:05 isAlmogK

This is only happing on mobile / tablet

Tested on the following

Tested On Android Phone / Nexus 5 / Chrome
Android Phone / S4 / Chrome Android Phone / S5 / Chrome iPad Mini / Chrome

isAlmogK avatar May 21 '15 16:05 isAlmogK

I just tested this issue on the GroundDB demo - http://grounddb.meteor.com/

and the outstanding methods: (Methods waiting to be sent) are deleted or lost if you close the browser tab

isAlmogK avatar May 21 '15 17:05 isAlmogK

The ground db demo is pretty old - is this still the case on the latest version?

raix avatar May 22 '15 09:05 raix

Yes this still happens with the latest version, which is what I'm using in my app. Basically once you close the browser tap you lose the methods that were saved

isAlmogK avatar May 22 '15 11:05 isAlmogK

@raix are you looking at fixing this based on this issue you really can't use GroundDB

isAlmogK avatar May 25 '15 19:05 isAlmogK

@raix we did some heavy tests here and the answer is quite 'simple' now: Mobile browsers can't handle this. The answer is the same. if you close your chrome, you lost your local storage and your progress.

Has anyone else had this issue?

isAlmogK avatar May 26 '15 12:05 isAlmogK

This seems to be an issue just with Chrome Mobile, we tested on Firefox mobile and it's fine

isAlmogK avatar May 27 '15 09:05 isAlmogK

@raix I've been working with @almogdesign in this issue and I've made a lot of tests, and here are the results.

Apparently mobile chrome has a bug with local storage. I've tested not just Ground DB, but lscache and amplify with it. We have another personal package that uses local storage and it is bugged too. I've did some tests cleaning cache, removing appcache, etc. The answer remains the same. At that point we started to try Firefox Mobile, and for our surprise it worked (local storage). This was tested in 4 different devices.

But we had another issue with FF, and here it is: You go online, switch to offline mode and create a new document. If you close firefox and reopen, now online, the document will be there if you call Collection.find().fetch(). But it will not sync (this on firefox mobile, chrome already cleared our data). At this point I don't have too much time to continue debugging, since this works in all desktop browsers. So I've created a little hack that is called on startup, it subscribes to my collection and then compare GroundDB docs (I've made this with Ground.lookup()) with my database, inserting the new ones.

That was our solution. @almogdesign also reported the bugs to some googlers. I think that with a little effort ground db can solve this by it self.

Thanks for support.

caioreis avatar May 27 '15 23:05 caioreis

perhaps we should add more storage adapters to the store package? - eg. use indexedDB when available or cordova stuff when available?

raix avatar May 28 '15 06:05 raix

btw. I did create a QA app for testing gdb: https://github.com/GroundMeteor/qa - not sure if it still passes or can be useful?

raix avatar May 28 '15 06:05 raix

You can view the bug report for chrome here - https://code.google.com/p/chromium/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Pri%20M%20Week%20ReleaseBlock%20Cr%20Status%20Owner%20Summary%20OS%20Modified&groupby=&sort=&id=492658

isAlmogK avatar May 28 '15 10:05 isAlmogK

bugger - I guess we should add more storage handlers then.

raix avatar May 28 '15 12:05 raix

@raix, I think that add more storage handlers will solve this and also create a more stable backup for apps that really need this. But we should probably do some tests before choosing the one since this behavior in chrome wasn't expected. It is possible to make your localstorage package more configurable? So we can add options over time. IndexedDB seems like a nice one, but I will sure use cordova suport soon.

caioreis avatar May 28 '15 17:05 caioreis

The Store package has a priority list - the best storage adapter at the top - so it will pick the best storage available. The storage adapters are async and if they have the same api as the localstorage adapter it should just work. The storage adapters register them selfs in the store package.

Store: https://github.com/GroundMeteor/store

Ranked storage: https://github.com/GroundMeteor/store/blob/master/client.js#L6-L8

Localstorage: https://github.com/GroundMeteor/localstorage

https://github.com/GroundMeteor/localstorage/blob/master/client.js#L112

I have tried localforage - but we need namespaced storage and events etc. (would also be nice to have a test package for storage adapters - making sure they comply with the api and works)

raix avatar May 28 '15 18:05 raix

Hey Guys, So this is a pretty big issue in chrome and it's recent with the last couple updates M42 you can see the full thread at - https://code.google.com/p/chromium/issues/detail?id=479767

And stackoverflow at http://stackoverflow.com/questions/29876790/localstorage-not-being-persisted-in-hybrid-app-in-android-m42/

It looks like a number of developers are moving towards IndexDB but this was fixed back in May 5th in the beta version. And I think with the todays update it works fine

isAlmogK avatar May 29 '15 13:05 isAlmogK

Any news on this issue? I still have the same problem with android app.

Login - online Subscribe - online Ground - online ( with {cleanupLocalData: false} ) Go ofline Update data - offline Close app - offline Go online Start app Login - online Subscribe - online Updated data is lost !! Everything is reverted back to server version !!

Result is same if I first subscribe then ground or first ground then subscribe. Every time it is reproducible.

barisro avatar Aug 25 '16 09:08 barisro

@barisro never had that fixed in my app. In my case, this was a crucial issue with this and other apps. I had to workaround using local files (inside the device) and using them as cache. Using this with GB fixed all my issues.

caioreis avatar Aug 28 '16 01:08 caioreis