Rails 可重复部分渲染增强

发布于 2025-01-08 13:54:38 字数 459 浏览 4 评论 0原文

有材料,其中一些有大约 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

没︽人懂的悲伤 2025-01-15 13:54:38

您是否真正测量过局部渲染会产生如此大的开销?

为什么您认为拖慢应用程序速度的不是必须呈现的一般视图代码(以及代码量)?

这里最简单的解决方案是不使用部分代码,而是复制代码并再次测试。

您还可以查看输出缓存或片段缓存

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文