Rails 可重复部分渲染增强
有材料,其中一些有大约 300 条评论甚至更多。所有评论都需要在没有寻呼机的情况下显示。
我以这种方式渲染它们:
<% comments.each do |comment|%>
<%= render "comments/comment", :comment => comment, :attachment => (attachment ||= false) %>
<% end %>
但在生产环境中返回页面需要 2.2 秒。
Completed 200 OK in 2624ms (Views: 2255.9ms | ActiveRecord: 79.4ms | Sphinx: 0.0ms)
(在 Rails 3.1.3、Ruby 1.9.2 上工作)
有没有加速渲染的方法?
There are matherials, some of them have about 300 comments and more. All comments need to be dispalyed without pager.
i am rendering them this way:
<% comments.each do |comment|%>
<%= render "comments/comment", :comment => comment, :attachment => (attachment ||= false) %>
<% end %>
but it takes 2.2 sec to return page in production env.
Completed 200 OK in 2624ms (Views: 2255.9ms | ActiveRecord: 79.4ms | Sphinx: 0.0ms)
(working on rails 3.1.3, Ruby 1.9.2)
Is there a method to speed up rendering?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否真正测量过局部渲染会产生如此大的开销?
为什么您认为拖慢应用程序速度的不是必须呈现的一般视图代码(以及代码量)?
这里最简单的解决方案是不使用部分代码,而是复制代码并再次测试。
您还可以查看输出缓存或片段缓存
Have you actually measured that the rendering of partial is inducing so much overhead?
Why do you assume that it's not the general view code that has to be rendered (and the volume of code) that slows the application down?
The simplest solution here would be to simply not use a partial but rather duplicate the code and test again.
You could also look into output caching or fragment caching