本文介绍了在 Ember 的 RestAdapter 上下文中,bulkCommit 是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

Ember Data 的 DS.RESTAdapter 包括一个 bulkCommit 属性.除了对批量提交与批量提交的一些模糊引用之外,我找不到任何关于它的作用/含义的文档.

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.

最初我认为这意味着我一次只能更新一条记录,但我目前将其设置为 false,并且我仍然能够同时更新多条记录使用:

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();

那么将 bulkCommit 设置为 false 和将其设置为 true 有什么区别?在什么情况下我会使用一种而不是另一种?

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?

推荐答案

REST 适配器支持批量提交,以便您可以在一次修改多个记录时提高性能.例如,假设您要创建 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();

这将导致 3 个 API 调用 POST '/people'.如果您启用 bulkCommit 功能

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();

然后 ember-data 将只对 POST '/people' 进行一次 API 调用,其中包含所有 3 条记录的详细信息.显然,并非每个 API 都会支持这一点,但如果您的 API 支持,它确实可以提高性能.

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 目前还没有相关文档,但您可以在以下单元测试中看到它的工作原理:创建几个人(使用bulkCommit)向/people 发送一个POST,带有一个数据散列数组

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

这篇关于在 Ember 的 RestAdapter 上下文中,bulkCommit 是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 10:22