How does Ember Data manage large amount of records?

时间:2015-09-01 22:02:33

标签: ember.js ember-data

I have been working with Ember Data and i'm trying to understand some concepts. I have a quite heavy data intensive app, my back-end has endpoints that return a lot of records.

So, basically i have Route's that have something like this.store.findAll('places') which can return thousands of places having each one several text intensive fields like services or description. This is only one of the resources, there are a few more that handle that amount of data as well.

My main concern is that the app hits some kind of limit or becomes unresponsive. So my question is that: How does Ember Data manage large amount of records ? Is there any best practice to handle those kind of scenarios ?

1 个答案:

答案 0 :(得分:3)

  

Ember Data如何管理大量记录?

与处理少量记录的方式相同。如果您尝试加载/获取大量记录,它不会对性能做任何特殊操作。你需要自己处理。

  

有没有最好的做法来处理这种情况?

不幸的是,没有。某种分页实际上是实现这一目标的唯一方法。但正如您在this thread中所看到的,对于“最佳”方式进行了相当多的讨论。有适用于此场景的适配器和插件,以及旨在简化操作的服务器端样板。但是真的没有规范的方式来对Ember Data进行分页。

在我看来,处理大量数据的最佳方法是设计一个查询端点并在服务器上实现它,自己处理所有事情。这将是最适合您的应用程序和最容易理解的。如果听起来很复杂,那就是因为它。数据集分割/分页不是一个简单的问题需要解决,你肯定会遇到问题。这就是为什么还没有达成一致意见的最佳实践。

更新:Javier Cadiz在评论中提到了JSON API,所以我想我会提到它。 JSON API似乎确实是Ember Data的新事实标准,它确实是specifiy a pagination方法。但是,JSON API相当新,尚未广泛采用。我相信直到最近,Ember Data才转而使用JSON API适配器作为默认设置。使用此分页很可能需要您遵循整个API,而不仅仅是分页方面。 (虽然你总是可以从中窃取某些想法。)因此,我不确定我是否还称它为最佳实践。

结论:JSON API的分页方式可能是未来的方式,但它目前还不是很受欢迎。 (虽然这仅仅是基于我所看到/读到的内容的意见。没有人说有多少人私下使用它。)

相关问题