如何提高渲染html的速度

时间:2021-10-17 03:53:49

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:

我确定:

  1. You are making queries inside your view
  2. 您正在视图中进行查询

  3. You are rendering a lot of partial
  4. 你渲染了很多偏

  5. You are nesting rendering partials
  6. 您正在嵌套渲染部分

  7. You are using expensive Ruby operations in your views (sorting, selecting, maping)
  8. 您在视图中使用了昂贵的Ruby操作(排序,选择,maping)

  9. You are nesting expensive operations (n2, n4... code)
  10. 您正在嵌套昂贵的操作(n2,n4 ...代码)

Examples, to explain it:

例子,解释一下:

  1. @my_objects = MyObject.where(:foo => :bar).all
  2. @my_objects = MyObject.where(:foo =>:bar).all

  3. @my_objects.each{ |object| render object }
  4. @ my_objects.each {| object |渲染对象}

  5. @my_objects.each{ |object| render object }
    _object.html.erb object.children.each{ |child| render child }
  6. @ my_objects.each {| object |渲染对象} _object.html.erb object.children.each {| child |渲染孩子}

  7. @my_objects.sort_by{ |a,b| a.id <=> b.id }
  8. @ my_objects.sort_by {| a,b | a.id <=> b.id}

  9. @my_objects.sort_by{ |a,b| a.map(&:id).last.name <=> b.map(&:id).last.name }
  10. @ 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:

我确定:

  1. You are making queries inside your view
  2. 您正在视图中进行查询

  3. You are rendering a lot of partial
  4. 你渲染了很多偏

  5. You are nesting rendering partials
  6. 您正在嵌套渲染部分

  7. You are using expensive Ruby operations in your views (sorting, selecting, maping)
  8. 您在视图中使用了昂贵的Ruby操作(排序,选择,maping)

  9. You are nesting expensive operations (n2, n4... code)
  10. 您正在嵌套昂贵的操作(n2,n4 ...代码)

Examples, to explain it:

例子,解释一下:

  1. @my_objects = MyObject.where(:foo => :bar).all
  2. @my_objects = MyObject.where(:foo =>:bar).all

  3. @my_objects.each{ |object| render object }
  4. @ my_objects.each {| object |渲染对象}

  5. @my_objects.each{ |object| render object }
    _object.html.erb object.children.each{ |child| render child }
  6. @ my_objects.each {| object |渲染对象} _object.html.erb object.children.each {| child |渲染孩子}

  7. @my_objects.sort_by{ |a,b| a.id <=> b.id }
  8. @ my_objects.sort_by {| a,b | a.id <=> b.id}

  9. @my_objects.sort_by{ |a,b| a.map(&:id).last.name <=> b.map(&:id).last.name }
  10. @ 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缓存(操作,片段......)