基本的な show アクションと、500 未満のオブジェクトを含むデータ セットがあります。
def show
@report = Report.find(params[:id])
@keywords = @report.keywords.order("total_value DESC")
end
パフォーマンス テストや最適化はまだ行っていませんが、なぜこのような小さなデータ セットで show アクションが非常に遅いのか理解できません。
ところで、私はアプリをローカルで使用しています。
編集: development.log
Started GET "/reports/2" for 127.0.0.1 at 2013-05-16 11:26:33 -0400
Processing by ReportsController#show as HTML
Parameters: {"id"=>"2"}
[1m[36mReport Load (0.2ms)[0m [1mSELECT "reports".* FROM "reports" WHERE "reports"."id" = ? LIMIT 1[0m [["id", "2"]]
[1m[35mKeyword Load (1.3ms)[0m SELECT "keywords".* FROM "keywords" WHERE "keywords"."report_id" = 2 ORDER BY total_value DESC
Rendered reports/show.html.erb within layouts/application (19552.2ms)
Rendered layouts/_header.html.erb (0.8ms)
Completed 200 OK in 19777ms (Views: 19773.0ms | ActiveRecord: 1.5ms)
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2013-05-16 11:26:52 -0400
Served asset /application.css - 304 Not Modified (39ms)
Started GET "/assets/pages.css?body=1" for 127.0.0.1 at 2013-05-16 11:26:52 -0400
Served asset /pages.css - 304 Not Modified (0ms)
Started GET "/assets/scaffolds.css?body=1" for 127.0.0.1 at 2013-05-16 11:26:52 -0400
Served asset /scaffolds.css - 304 Not Modified (0ms)
Started GET "/assets/styles.css?body=1" for 127.0.0.1 at 2013-05-16 11:26:52 -0400
Served asset /styles.css - 304 Not Modified (2ms)
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2013-05-16 11:26:52 -0400
Served asset /jquery.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-transition.js?body=1" for 127.0.0.1 at 2013-05-16 11:26:52 -0400
Served asset /bootstrap-transition.js - 304 Not Modified (0ms)
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2013-05-16 11:26:52 -0400
Served asset /jquery_ujs.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-affix.js?body=1" for 127.0.0.1 at 2013-05-16 11:26:52 -0400
Served asset /bootstrap-affix.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-alert.js?body=1" for 127.0.0.1 at 2013-05-16 11:26:52 -0400
Served asset /bootstrap-alert.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-button.js?body=1" for 127.0.0.1 at 2013-05-16 11:26:52 -0400
Served asset /bootstrap-button.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-carousel.js?body=1" for 127.0.0.1 at 2013-05-16 11:26:52 -0400
Served asset /bootstrap-carousel.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-collapse.js?body=1" for 127.0.0.1 at 2013-05-16 11:26:52 -0400
Served asset /bootstrap-collapse.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-dropdown.js?body=1" for 127.0.0.1 at 2013-05-16 11:26:52 -0400
Served asset /bootstrap-dropdown.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-modal.js?body=1" for 127.0.0.1 at 2013-05-16 11:26:52 -0400
Served asset /bootstrap-modal.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-scrollspy.js?body=1" for 127.0.0.1 at 2013-05-16 11:26:52 -0400
Served asset /bootstrap-scrollspy.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-tab.js?body=1" for 127.0.0.1 at 2013-05-16 11:26:52 -0400
Served asset /bootstrap-tab.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-tooltip.js?body=1" for 127.0.0.1 at 2013-05-16 11:26:52 -0400
Served asset /bootstrap-tooltip.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-popover.js?body=1" for 127.0.0.1 at 2013-05-16 11:26:52 -0400
Served asset /bootstrap-popover.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-typeahead.js?body=1" for 127.0.0.1 at 2013-05-16 11:26:52 -0400
Served asset /bootstrap-typeahead.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap.js?body=1" for 127.0.0.1 at 2013-05-16 11:26:52 -0400
Served asset /bootstrap.js - 304 Not Modified (0ms)
Started GET "/assets/keywords.js?body=1" for 127.0.0.1 at 2013-05-16 11:26:52 -0400
Served asset /keywords.js - 304 Not Modified (0ms)
Started GET "/assets/pages.js?body=1" for 127.0.0.1 at 2013-05-16 11:26:52 -0400
Served asset /pages.js - 304 Not Modified (0ms)
Started GET "/assets/reports.js?body=1" for 127.0.0.1 at 2013-05-16 11:26:52 -0400
Served asset /reports.js - 304 Not Modified (0ms)
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2013-05-16 11:26:52 -0400
Served asset /application.js - 304 Not Modified (1ms)
Started GET "/assets/logo.png" for 127.0.0.1 at 2013-05-16 11:26:53 -0400
Served asset /logo.png - 304 Not Modified (0ms)
意見
<table class ="table table-striped">
<tr>
<th>Keyword</th>
<th>Avg position</th>
<th>Total revenue</th>
</tr>
<% @keywords.each do |keyword| %>
<tr>
<td><%= keyword.description %></td>
<td><%= keyword.avg_position %></td>
<td><%= keyword.total_value %></td>
</tr>
<% end %>
</table>