michaellperry / jinaga

Universal web back-end, offering an application-agnostic API, real-time collaboration, and conflict resolution.
http://jinaga.com
MIT License
35 stars 3 forks source link

Optimize saving a fact with a previously unsaved predecessor #27

Closed michaellperry closed 6 years ago

michaellperry commented 6 years ago

Reproduction steps:

Use j.fact to create a new fact that has an unsaved predecessor. For example:

j.fact({
  predecessor: {
    value: 'Never seen before',
    root: {
      value: 'This one already existed'
    }
  },
  value: 'Brand new, too'
}

Outcome

The client generates two save requests to the server. The second includes the predecessor, so the first was not necessary.

Expected behavior

The client should collect the entire tree of facts that it is attempting to save, and issue just one save call to the server.

michaellperry commented 6 years ago

The client application was explicitly calling j.fact twice. Jinaga is correctly optimizing the save requests if the application calls j.fact once.