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

Consistent ID generation #167

Closed jer-sen closed 8 years ago

jer-sen commented 8 years ago

Hi,

The Meteor implementation of "Consistent ID generation and optimistic UI" (described in http://guide.meteor.com/methods.html) is not respected when GroundDB resumes a method.

You can follow these steps to see this:

  1. When off-line : call a Meteor method added to Ground.methodResume and that uses insert to insert a new document in a Ground collection
  2. Always off-line : refresh the web page in the browser
  3. When on-line : GroundDB resumes the method but document inserted on the server don't have the same id than the one inserted on the client when off-line

It is a big issue since, if this id has been used off-line after insertion by other methods (to update or delete the new document), then resuming these methods will fail.

GroundDB should save and restore the seed (used to generate new ids) sent to the server with method's arguments.

Note that a workaround exists: give a seed to the method through an argument, then inside the method generate ids by yourself (i.e with Random package) for the _id field of the inserted documents and generate new seeds for methods called inside the method.

Thanks in advance.