1

Ember Data's DS.RESTAdapter includes a bulkCommit property. I can't find any documentation about what this does/means, other than some vague references to batch committing vs bulk committing.

Initially I assumed it would mean I could only update a single record at a time, but I currently have it set to false, and I'm still able to update multiple records at the same time using:

this.get('store').commit();

So what is the difference between setting bulkCommit to false and setting it to true? In what situation would I use one instead of the other?

Undistraction
  • 42,754
  • 56
  • 195
  • 331

1 Answers1

3

The REST adapter supports bulk commits so that you can improve performance when modifying several records at once. For example, let's say you want to create 3 new records.

var tom = store.createRecord(Person, { name: "Tom Dale" });
var yehuda = store.createRecord(Person, { name: "Yehuda Katz" });
var mike = store.createRecord(Person, { name: "Mike Grassotti" });
store.commit();

This will result in 3 API calls to POST '/people'. If you enable the bulkCommit feature

set(adapter, 'bulkCommit', true);
var tom = store.createRecord(Person, { name: "Tom Dale" });
var yehuda = store.createRecord(Person, { name: "Yehuda Katz" });
var mike = store.createRecord(Person, { name: "Mike Grassotti" });
store.commit();

then ember-data will make just one API call to POST '/people' with details for all 3 records. Obviously not every API is going to support this, but if yours does it can really improve performance.

AFAIK there is not documentation for this yet but you can see it working in the following unit test: creating several people (with bulkCommit) makes a POST to /people, with a data hash Array

Mike Grassotti
  • 19,040
  • 3
  • 59
  • 57
  • I think this is deprecate. The last part of [TRANSITION.md](https://github.com/emberjs/data/blob/master/TRANSITION.md#transaction-is-gone-save-individual-records) explains how to do a bulk save in Ember Data v.1.0 – Valer Dec 16 '13 at 14:49
  • 3
    My mistake. It's not using a single request: "If you want to batch up a bunch of records to save and save them all at once, you can just put them in an Array and call .invoke('save') when you're ready. We plan to support batch saving with a single HTTP request through a dedicated API in the future." – Valer Dec 16 '13 at 16:16