【发布时间】:2013-05-30 13:30:41
【问题描述】:
我正在开发基于 angularjs 和 rails 的单页应用程序。我使用 RABL 来渲染 JSON 文件。 很多 JSON 响应都需要这样的嵌套属性
child :tags do
attributes :id, :name
end
child webapp.comments do |t|
// with other nested attributs like user for comments...
extends "comments/index"
end
child webapp.category do |t|
attributes :id, :name
end
child webapp.user do |t|
extends 'users/show-lazy'
end
node(:image_url) { |webapp| webapp.image_url(:medium) }
我有一些性能问题,因为 RABL 渲染视图大约需要 800 毫秒(有一个用户请求!)(Active Record,只需 50 毫秒)。它太长了。我还没有激活缓存。根据 Github https://github.com/nesquena/rabl/issues/49 上的这个相关问题,嵌套属性会减慢渲染速度...
我的问题:如果嵌套属性的生成需要很长时间,发送不同的请求是否更好,例如: 获取 /myresource 获取 /cmets/:id/myresource 获取 /tags/:id/myresource
你的意见是什么?
【问题讨论】:
-
答案取决于很多事情......网络与服务器相关的延迟有多少,有多少数据,您对 API 有多少控制权等等。我更喜欢分块当我可以在需要详细信息之前向用户显示某些内容时。
标签: ruby-on-rails json performance rabl