What Does bulkCommit Mean In The Context Of Ember&

2019-04-16 11:42发布

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?

1条回答
叼着烟拽天下
2楼-- · 2019-04-16 12:09

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

查看更多
登录 后发表回答