Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.0] observeSource API / docs confusing #183

Open
damonmaria opened this issue Oct 27, 2016 · 7 comments
Open

[2.0] observeSource API / docs confusing #183

damonmaria opened this issue Oct 27, 2016 · 7 comments

Comments

@damonmaria
Copy link

I had assumed that observeSource would make the GroundDB collection match the collection it was observing. But that doesn't appear to be the case. I think I need to call keep first to make the collections match and then observeSource to keep it up to date, otherwise old records might be lying around in the GroundDB collection.

I can understand the need for both cases. Should there be a different method or some options to choose to leave records not matching the cursor?

Combining these two steps could also be more efficient since at the moment observeSource will run through all the existing docs again to do the initial added just after keep has. If there was a combined call then _suppress_initial could be used and the existing docs updated while calculating the ones to remove.

@raix
Copy link

raix commented Oct 27, 2016

what problem are you trying to solve? If you have data added by the user in offline mode you could do something like:

  const fooRemote = new Mongo.Collection('foo');
  const foo = new Ground.Collection('foo');
  foo.observeSource(fooRemote.find());
  Meteor.subscribe('foo', () => {
    // keep only current sub and data added offline
    foo.keep(fooRemote.find(), foo.find({ addedOffline: true }));
    foo.find({ addedOffline: true }).forEach((doc) => {
      // add the document to the remote db?
      fooRemote.insert(_.omit(doc, 'addedOffline'));
    });
  });

@damonmaria
Copy link
Author

For this particular collection I'm just trying to keep a mirror offline. And that is what I had assumed observerSource would do. So at the moment I'm:

  const OrgProfiles = new Mongo.Collection('orgProfiles')
  const OrgProfilesMirror = new Ground.Collection('orgProfilesMirror')
  Tracker.autorun(() => {
    const subscription = Meteor.subscribe('orgProfiles.selectionList')
    if (subscription.ready()) {
      const orgProfilesCursor = OrgProfiles.find()
      OrgProfilesMirror.keep(orgProfilesCursor)
      OrgProfilesMirror.observeSource(orgProfilesCursor)
    }
  }

So wondering if there should be a method to do this (which could probably be more efficient that what I have here).

@raix
Copy link

raix commented Oct 28, 2016

  const OrgProfiles = new Mongo.Collection('orgProfiles')
  const OrgProfilesMirror = new Ground.Collection('orgProfilesMirror')
  OrgProfilesMirror.observeSource(orgProfiles.find())

  const subscription = Meteor.subscribe('orgProfiles.selectionList')

  Tracker.autorun((c) => {
    if (subscription.ready()) {
      c.stop();
      OrgProfilesMirror.keep(OrgProfiles.find())
    }
  }

@damonmaria
Copy link
Author

Thanks. I see. And this is efficient in terms of access to the storage as keep only operates on what needs to be deleted.

To avoid opening another issue for a question. When observeSource calls setDocument it's EJSON.clone()ing it. So we end up with 2 copies in memory. Is the clone necessary? I would imagine for most that document isn't modified. Or could it be an option to not clone?

@raix
Copy link

raix commented Oct 29, 2016

Sure we could add an option eg. "ForceImmutable"?

@damonmaria
Copy link
Author

That would be perfect.

@flippyhead
Copy link

We too are considering GroundDB for this use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants