Meteor-Community-Packages / ground-db

GroundDB is a thin layer providing Meteor offline database and methods
https://atmospherejs.com/ground/db
MIT License
569 stars 76 forks source link

Running into a wried discount issue with data lose using GroundDB #94

Open isAlmogK opened 9 years ago

isAlmogK commented 9 years ago

So were running into some wried discount issue with GroundDB, if our app goes from offline to online and their is a internet disconnection were seeing the app refresh and the local data that was saved via GroundDB is lost and was never upload.

It seems that the app clears the local storage before it was uploaded.

Has anyone else had this issue?

rafaelquintanilha commented 9 years ago

Hard to tell without seeing any code. You mean your data is always lost when you have a disconnection or there is any other case when it works properly?

isAlmogK commented 9 years ago

Yes I get a internet disconnection the app goes into offline mode everything is fine but then when the app connects again it refreshes deletes the current local data and re saves. It's overwriting the local data.

The code is based on the examples provided but I am using iron-router

joaopiopedreira commented 9 years ago

Hi almogdesign, in order not to loose previously saved data in the client, you might want to try to ground your collections in this way (according to the documentation):

var groundList = new Ground.Collection('list', {
   cleanupLocalData: false
});

This way, your client data will not be overwritten and only changed records will be added/removed/changed.

If you have large collections on the client, you might want to try this fix. It worked for me.

Bear in mind that after the app refreshes (offline to online transition), you loose all you Session variables and are thus not able to bring the user to where he was prior to the reload. To overcome that, I started using persistent Session vars (take a look here). At least now I can take the user exactly where he was before the reload, which it good (had a lot of complaints before this change...). I use the "auth" version for persistence: Session vars are kept since a the user logs in and removed once he logs out. Very helpful!

Also, watch out for the Ground.ready() hook. When online, it works fine but if you are offline it hangs and it never reports "true".

I'm currently using GroundDB together with mdg's appcache in a web/mobile app. It's been a challenge to control all this page reload / data re-fetch behaviour but I think I'm getting there. I'm happy to exchange my experience with you in case you need further assistance.

My ultimate challenge now is to solve this very strange issue (with cordova):

Now, how strange is that?

Cheers and good luck!

raix commented 9 years ago

create a package for appcache only adding it when on the web platform - don't use it on cordova..

isAlmogK commented 9 years ago

@joaopiopedreira this is really great thanks for the help will be testing it out today. Bye the way you can use amplifyjs for the sessions.

isAlmogK commented 9 years ago

@raix @joaopiopedreira I'm not sure the issue is due to cordova, we also this issue with certain tablets. The tablet would go offline and once there was a wifi connection it would not go back online. It was Samsung Tab tablets were still looking into this.

joaopiopedreira commented 9 years ago

@raix, but how does a Cordova app behaves when offline without appcache? Will it still work?

Are there any improvements in the works in order to make appcache play nicer with Cordova?

Thanks

Enviado do meu iPhone

No dia 04/05/2015, às 06:41, Morten N.O. Nørgaard Henriksen notifications@github.com escreveu:

create a package for appcache only adding it when on the web platform - don't use it on cordova..

— Reply to this email directly or view it on GitHub.

isAlmogK commented 9 years ago

@joaopiopedreira can we connect on Skype / email would like to learn more about your experience. I think we're both doing the same and running into the same issues

joaopiopedreira commented 9 years ago

Sure Almog, if today is a good day for you, it's fine for me (bank holiday in the UK). I'm doing some catch-up work in the hotel.

Skype name: joaopiopedreira

Cheers,

Enviado do meu iPhone

No dia 04/05/2015, às 10:29, Almog Koren notifications@github.com escreveu:

@joaopiopedreira can we connect on Skype / email would like to learn more about your experience. I think we're both doing the same and running into the same issues

— Reply to this email directly or view it on GitHub.

isAlmogK commented 9 years ago

@rafaelquintanilha great

joaopiopedreira commented 9 years ago

Hi @raix, would you tell me how to do that (create a package only for a certain platform)?

Many thanks,

Enviado do meu iPhone

No dia 04/05/2015, às 06:41, Morten N.O. Nørgaard Henriksen notifications@github.com escreveu:

create a package for appcache only adding it when on the web platform - don't use it on cordova..

— Reply to this email directly or view it on GitHub.

raix commented 9 years ago
Package.describe({
  name: 'browserappcache',
  summary: 'Only add appcache to browsers'
});

Package.onUse(function(api) {
  api.use('appcache', ['web.browser', 'server']);
});
joaopiopedreira commented 9 years ago

Thank you @raix, appreciated :)

One more, pretty please:

I have two large collections that do not change much (server side) and are never modified client side.

Do you think it's a good idea to copy them into a client only collection on start up and ground them as such (to avoid ground:db having to subscribe to them on every reconnect, erasing and recreating them?

Thanks

Enviado do meu iPhone

No dia 06/05/2015, às 20:11, Morten N.O. Nørgaard Henriksen notifications@github.com escreveu:

Package.describe({ name: 'browserappcache', summary: 'Only add appcache to browsers' });

Package.onUse(function(api) { api.use('appcache', ['web.browser', 'server']); }); — Reply to this email directly or view it on GitHub.

raix commented 9 years ago

@joaopiopedreira if the two collections never change you could have something like:

  var foo = new Ground.Collection('foo', { cleanupLocalData: false });

  Meteor.startup(function() {
    if (!foo.findOne()) {
      Meteor.subscribe('foo', function() {
        // Manually triggering a clean up of local only data
        groundList.removeLocalOnly(); 
      });
    } else {
      // Got data already
    }
  });
joaopiopedreira commented 9 years ago

Got it! Thank you very much @raix :-)

On 7 May 2015 at 08:10, Morten N.O. Nørgaard Henriksen < notifications@github.com> wrote:

@joaopiopedreira https://github.com/joaopiopedreira if the two collections never change you could have something like:

var foo = new Ground.Collection('foo', { cleanupLocalData: false });

Meteor.startup(function() { if (!foo.findOne()) { Meteor.subscribe('foo', function() { // Manually triggering a clean up of local only data groundList.removeLocalOnly(); }); } else { // Got data already } });

— Reply to this email directly or view it on GitHub https://github.com/GroundMeteor/db/issues/94#issuecomment-99751233.