My rails app works fine, but is too slow in rendering from DB. Example: "Completed in 4027ms (View: 3758, DB: 87)". Rails 2.3.8. How can I improve the html render speed in rails apps?
我的rails应用程序工作正常,但从DB渲染速度太慢。示例:“在4027ms完成(查看:3758,DB:87)”。 Rails 2.3.8。如何提高rails应用程序中的html渲染速度?
USING: action.html.erb
2 个解决方案
#1
7
I am sure:
我确定:
- You are making queries inside your view
- You are rendering a lot of partial
- You are nesting rendering partials
- You are using expensive Ruby operations in your views (sorting, selecting, maping)
- You are nesting expensive operations (n2, n4... code)
您正在视图中进行查询
你渲染了很多偏
您正在嵌套渲染部分
您在视图中使用了昂贵的Ruby操作(排序,选择,maping)
您正在嵌套昂贵的操作(n2,n4 ...代码)
Examples, to explain it:
例子,解释一下:
- @my_objects = MyObject.where(:foo => :bar).all
- @my_objects.each{ |object| render object }
- @my_objects.each{ |object| render object }
_object.html.erb object.children.each{ |child| render child } - @my_objects.sort_by{ |a,b| a.id <=> b.id }
- @my_objects.sort_by{ |a,b| a.map(&:id).last.name <=> b.map(&:id).last.name }
@my_objects = MyObject.where(:foo =>:bar).all
@ my_objects.each {| object |渲染对象}
@ my_objects.each {| object |渲染对象} _object.html.erb object.children.each {| child |渲染孩子}
@ my_objects.sort_by {| a,b | a.id <=> b.id}
@ my_objects.sort_by {| a,b | a.map(&:id).last.name <=> b.map(&:id).last.name}
#2
2
1/ Probably you are making lots of things in your view (ordering or something). You could ask MySQL to do more job.
1 /您可能在视图中做了很多事情(订购或其他事情)。你可以要求MySQL做更多的工作。
2/ You can use rails caching (actions, fragments ...)
2 /您可以使用rails缓存(操作,片段......)
#1
7
I am sure:
我确定:
- You are making queries inside your view
- You are rendering a lot of partial
- You are nesting rendering partials
- You are using expensive Ruby operations in your views (sorting, selecting, maping)
- You are nesting expensive operations (n2, n4... code)
您正在视图中进行查询
你渲染了很多偏
您正在嵌套渲染部分
您在视图中使用了昂贵的Ruby操作(排序,选择,maping)
您正在嵌套昂贵的操作(n2,n4 ...代码)
Examples, to explain it:
例子,解释一下:
- @my_objects = MyObject.where(:foo => :bar).all
- @my_objects.each{ |object| render object }
- @my_objects.each{ |object| render object }
_object.html.erb object.children.each{ |child| render child } - @my_objects.sort_by{ |a,b| a.id <=> b.id }
- @my_objects.sort_by{ |a,b| a.map(&:id).last.name <=> b.map(&:id).last.name }
@my_objects = MyObject.where(:foo =>:bar).all
@ my_objects.each {| object |渲染对象}
@ my_objects.each {| object |渲染对象} _object.html.erb object.children.each {| child |渲染孩子}
@ my_objects.sort_by {| a,b | a.id <=> b.id}
@ my_objects.sort_by {| a,b | a.map(&:id).last.name <=> b.map(&:id).last.name}
#2
2
1/ Probably you are making lots of things in your view (ordering or something). You could ask MySQL to do more job.
1 /您可能在视图中做了很多事情(订购或其他事情)。你可以要求MySQL做更多的工作。
2/ You can use rails caching (actions, fragments ...)
2 /您可以使用rails缓存(操作,片段......)