【发布时间】:2015-11-01 16:22:47
【问题描述】:
这个控制台输出看起来正常吗?
16:10:01 rails.1 | 2015-11-01 16:10:01 开始为 10.0.2.2 获取“/” +0000 16:10:02 轨道.1 | PagesController#home 处理为 HTML 16:10:02 rails.1 | (1.5 毫秒)从“公园”16:10:02 rails.1 | SELECT COUNT() (1.0ms) SELECT COUNT() FROM "trains" WHERE "trains"."superseded_at" IS NULL 16:10:02 rails.1 |火车负载(10.9 毫秒)选择“火车”。* 从“火车”按“火车”排序。“火车排序”ASC 16:10:02 rails.1 |循环负载 (26.6 毫秒) SELECT "cycles".* FROM "cycles" WHERE "cycles"."train_id" IN (22147, 21958, 22055, 22059, 22356, 22045, 22001, 22072, 21836, 22000, 21800, 22042, 22373,21818,22024,22364,22365,22168,22060,22242,22054,22060,21899,22392,22117,21920,21822,22354,219201,21931,22354,21834,21931,21826,21834,22306,21970,21980,21791,21790, 21961,22037,21955,21985,22191,22391,21870,22004,22180,22164,22383,22405,22161,22169,22254,21812,22031,22219,22063,22193,22028,22063,21873,22028,22232,21942,22175,21953, 21787,22251,21900,22206,22066,21793,22390,22066,21783,22376,22083,2115,22346,22083,21932,22011,21913,21932,22011,22394,2225,21866,22328,22324,21839,22328,22324,21839,21939,22021,22087, 22290,22027,21993,22065,22187,2196,21902,21861,21963,21952,21861,2193,21952,22304,2293,22284,22279,22269,21848,22279,21855,21854,22209,21855,21854,22209,21857,21784,22188,22178,22181, 22166、22146、21883、22239、22137、22135、21903、22133、22127、22099、22098、22095、22090、21912、22096、22398、221937、222222、 1936,22006,2198,22361,22380,22023,21979,21810,22351,22204,22357,22396,22240,22198,22139,22211,22198,22139,22294,2297,22026,22344,2197,22026,22344,21959,22082,22094, 22067,21974,22129,22141,22384,21809,22141,22384,2234,22404,2243,22049,21881,22409,22159,21881,22409,22159,21829,21846,2185,21878,21890,21897,21878,21890,21897,21910,21919,22221,22228, 21934,21935,21977,21994,22044,22051,22046,22047,22062,22084,22103,22109,22124,22237,22121,22124,22237,22241,22142,22184,22189,22196,22184,22189,22196,21789,22255,22256, 22314,22368,22371,22411,21992,22124,22100,22056,22322,22020,22165,22203,22010,22227,22149,22015,22353,22275,22015,22353,22032,22064,2274,22032,22064,21989,22310,22330,22330, 22245,21823,22183,22374,21884,21908,22119,22105,22025,22319,21838,22002,22048,21850,21865,22085,21850,21865,22085,22143,22285,2124,22102,22323,22073,21909,21786,22318, 22151、22077、21799、22113、22316、21803、22308、22289、21840、22271、22366、22185、21951、21871、21945、21802、22199、22336、 22007,21796,22343,22305,22195,2238,22226,22192,2249,22217,221330,22120,22296,22307,21990,22043,22307,2190,22043,21987,21907,22138,21815,21907,22138,21815,22112,22231,21949, 21978,21950,21969,22375,22367,22362,21940,21933,21930,21929,22332,22016,22327,22019,22298,22038,2223,22268,2203,21923,22268,22259,2229,22267,22259,22253,21851,21853, 22194,22068,21869,22190,22102,22079,22148,22402,22236,22097,21915,22101,22128,22129,22400,22111,22128,21896,22281,21828,21896,22281,21794,22320,21797,21794,22320,21797,22326,21806,21981, 21964,22378,22370,22013,22291,22295,22093,2222,21795,22108,22272,21921,22340,22012,22399,22110,22012,22286,22041,22218,21798,22041,22218,21798,22177,22089,21967,21886, 22282,21960,22359,22358,21821,22395,21971,22207,21973,21876,21973,21876,22408,22174,22125,21898,22091,22238,22403,22248,2238,22144,22081,22237,22144,22081,22076,21891,22170,22173, 21874、22176、22182、21867、22406、22197、22200、22205、21986、22058、21847、21792、22057、21845、22263、22407、22260、22270、 22266,22393,21844,22280,2203018,22342,21824,21946,22342,21824,21946,21827,21819,21999,22413,21819,2199,22413,21814,2114,21817,21814,22381,22389,21814,22381,22389,22382,21997,21954,22115, 21905,21860,21901,22311,22193,21816,22311,21991,21816,22363,22114,21938,22186,22179,21928,22183,22179,21928,22092,22360,22022,22092,21864,21831,22074,22257,22003,22131, 22388,21894,22349,22337,22348,21996,22140,21825,22347,21966,22132,22345,22352,22152,22202,22210,22075,22088,2212,22134,22118,22086,22134,22118,22086,22171,21922,22107, 21917,21868,21879,22158,22386,22157,21841,21957,22163,21842,21843,22155,22220,22287,22040,22069,22201,22071,22061,22078,22071,22061,22078,22071,22053,22078,21895,22053,21914,22212,22080, 22300,22412,22213,22301,22154,22153,21832,21801,22145,21906,21911,21995,22224,21904,21856,21852,22252,22385,22264,22052,21984,22235,21811,22246,21956, 21892、22288、22039、21888、21837、22292、22036、22035、21968、22303、22034、21925、21941、22312、21927、22321、22317、21962 ,22325,22331,22329,22339,21813,21877,21875,21976,21877,21875,21976,22410,22225,21965,22341,22335,21965,22341,22233,22334,22005,2233,22334,22005,22333,22315,21988,22029,21835,21858,22276 22050,21862,21882,22273,22262,2261,22265,21872,21785,22009,21947,2185,22214,21947,21893,22214,21944,2182,22008,22216,2182,22033,22223,21972,22156,22223,21972,22156,22223,22377,22162,22377,22162 ,22070,21948,22167,22136,22355,22350,22379,21830,21975,22372,21943,22258,22017,21918,21859,22017,21918,21859,21808,21889,21807,22283,22150,22244,22014,21833)16:10 :02 轨道.1 | (0.6 毫秒)从“照片”16:10:03 rails.1 | SELECT COUNT(*)在布局/应用程序中渲染页面/home.html.erb (0.4ms) 16:10:03 rails.1 |渲染 shared/_svg.html.erb (0.6ms) 16:10:03 rails.1 |渲染 shared/_svg.html.erb (0.1ms) 16:10:04 rails.1 |渲染 shared/_banner_slideshow.html.erb (0.1ms) 16:10:04 rails.1 |渲染 shared/_flash_messages.html.erb (0.4ms) 16:10:04 rails.1 |渲染 shared/_svg.html.erb (0.1ms) 16:10:04 rails.1 |渲染 shared/_svg.html.erb (0.1ms) 16:10:04 rails.1 |渲染 shared/_svg.html.erb (0.1ms) 16:10:04 rails.1 |渲染 shared/_svg.html.erb (0.1ms) 16:10:04 rails.1 |渲染 shared/_svg.html.erb (0.1ms) 16:10:04 rails.1 |在 2414 毫秒内完成 200 OK(查看次数:2033.0 毫秒 | ActiveRecord:40.6 毫秒)
为什么渲染的各个部分花费不到 1 毫秒,但总 Views 渲染却超过 2 秒?
home.html.erb:- 我清空了这个,看看这里是否有什么东西导致了缓慢,但即使输出一个单词,总视图渲染时间也超过 2 秒。
blah
_svg.html.erb:
<svg role="img" aria-labelledby="title desc" class="<%= classs if local_assigns[:classs] %>">
<% if local_assigns[:title] %>
<title id="title"><%= title %></title>
<% end %>
<% if local_assigns[:description] %>
<desc id="desc"><%= description %></desc>
<% end %>
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#<%= hash %>"></use>
</svg>
_banner-slideshow.html.erb:
<div class="gallery banner banner--slideshow">
<div class="gallery__slide"></div>
<div class="gallery__slide"></div>
<div class="gallery__slide"></div>
<div class="gallery__slide"></div>
</div>
_flash-messages.html.erb:
<% if flash.any? %>
<% flash.each do |type, message| %>
<%= render partial: 'shared/flash_message', locals: { type: type, message: message } %>
<% end %>
<% end %>
_flash-message.html.erb:
<div class="message-box message-box--<%= type %>">
<a class="close" data-dismiss="alert">×</a>
<%= message %>
</div>
【问题讨论】:
-
您可以粘贴视图吗?也许问题是视图中的 N+1 个查询
-
@matanco 向 OP 添加了视图
标签: ruby-on-rails views rendering