此控制台输出看起来是否正常?
16:10:01 rails.1 |开始GET" /" for 10.0.2.2 at 2015-11-01 16:10:01 +0000 16:10:02 rails.1 |由PagesController处理#home为HTML 16:10:02 rails.1 | (1.5ms)SELECT COUNT()FROM" parks" 16:10:02 rails.1 | (1.0ms)SELECT COUNT()FROM" train"在哪里"火车"。" superseded_at" IS NULL 16:10:02 rails.1 |列车负载(10.9ms)SELECT" train"。* FROM" train"订购"火车"。" train_sort" ASC 16:10:02 rails.1 |循环加载(26.6ms)SELECT"循环"。* FROM"循环"在哪里"周期"。" train_id" IN(22147,21958,22055,22059,22356,22045,22001,22072,21836,22000,21800,22042,22373,21818,22024,22364,22365,22168,21863,22242,22054,22060,21899,22392, 22117,21920,21822,22354,22401,21931,21826,21834,22306,21970,21980,21791,21790,21961,22037,2195,21985,22191,22391,21870,22004,22180,22164,22383,22405, 22161,22169,22254,21812,22031,22219,22063,21887,22028,22232,21942,22175,21953,21787,22251,21900,22206,21805,21793,22390,22066,21783,22376,22083,22415, 22346,21913,21932,22011,22394,22250,2186,22328,22324,21883,21939,22021,22087,22290,22027,21993,22065,22187,22278,21902,21861,21963,21952,22304,22293, 22284,22279,22269,21884,21788,2185,2185,22209,21857,2174,22188,22178,22181,22166,22146,21883,22239,22137,22135,21903,22133,22127,22099,22098,22095, 22090,21912,22096,22398,22397,22222,21937,21936,22006,21998,22361,22380,22023,21979,21810,22351,22204,22357,22 396,22240,22198,22208,22211,21992,22139,22294,2229,22026,22344,21995,22082,22094,22067,21974,22106,22126,22277,21809,22141,22384,22234,22404,22243, 22049,21881,22409,22159,21829,21884,218855,21878,21890,21897,21910,21919,22221,22228,21934,21935,21977,21994,22044,22051,22046,22047,22062,22084,22103, 22109,22123,22116,22121,22124,22237,22241,22142,22184,22189,22196,21789,22255,22256,22314,22368,22371,22411,21992,22104,22100,22056,22322,22020,22165, 22203,22010,22227,22149,22015,22353,22275,21880,22274,22032,22064,21989,22310,22330,22245,21823,22183,22374,21888,21908,22119,22105,22025,22319,218838, 22002,22048,21850,21865,22085,22143,22285,21924,22102,22323,22073,21909,21786,22318,22151,22077,21799,22113,22316,21803,22308,22289,21840,22271,22366, 22185,21951,21887,21945,21802,22199,22336,22007,2176,22343,22387,21916,22305,22195,22338,22226,22192,22249,2 2217,22130,22120,22296,22307,21990,22043,21987,21907,22138,21815,22112,22231,21949,21978,21950,21969,22375,22367,22362,21940,21933,21930,21992,22332, 22016,22327,22019,22298,22038,21923,22268,21804,22229,22267,22259,22253,2185,21853,22194,22068,21869,22190,22160,22079,22148,22402,22236,22097,21915, 22101,22128,22129,22400,22111,21828,21889,22281,21794,22320,2177,22326,21806,21981,21964,22378,22370,22013,22291,22295,22093,22122,21795,22108,22272, 21921,22340,22012,22399,22110,22299,22286,22041,22218,21798,22177,22089,21967,21888,2222,21960,22359,22358,21821,22395,21971,22207,21973,21887,22408, 22174,22125,21898,22091,22238,22403,22248,21888,22144,22081,22076,21891,22170,22173,2187,22176,22182,21886,22406,22197,22200,22205,21986,22058,21847, 21792,22057,21845,22263,22407,22260,22270,22266,22393,21844,22280,22030,22309,21982,22018,22342,21824,21946, 21827,21819,21999,22413,22369,22414,21817,21814,22381,22389,22382,21997,2195,22115,21905,21860,21901,22311,22193,22230,22313,21991,21816,22363,22114, 21938,22186,22179,21928,21983,22360,22022,22092,21864,21831,22074,22257,22003,22131,22388,21889,22349,22337,22348,21996,22140,21825,22347,21966,22132, 22345,22352,22152,22202,22210,22075,22088,22172,22134,22118,22086,22171,21922,22107,21917,21886,21879,22158,22386,22157,21846,21955,22163,21884,218843, 22155,22220,22287,22040,22069,22201,22071,22061,22078,21895,22053,21914,22212,22080,22300,22412,22213,22301,22154,22153,21832,21801,22145,21906,21911, 21995,22224,21904,2185,2185,22252,22385,22264,22052,21984,22235,21811,22246,2195,21892,22288,22039,21888,21883,22292,22036,22035,21968,22303,22034, 21925,21941,22312,21923,22321,22317,21962,22325,22331,22329,22339,21813,21877,21875,21976,22410,22225,22247, 22215,22335,21965,22341,22233,22334,22005,22333,22315,21988,22029,21835,2185,22276,22050,21886,21882,22273,22262,22261,22265,21878,2175,22009,21947, 21893,22214,21944,21820,22008,22216,22302,22033,22223,21972,22156,21849,22377,22162,22070,21948,22167,22136,22355,22350,22379,21830,21975,22372,21943, 22258,22017,21918,2185,21808,21888,21807,22283,22150,22244,22014,21833)16:10:02 rails.1 | (0.6ms)SELECT COUNT(*)FROM" photos" 16:10:03 rails.1 |在layouts / application(0.4ms)16:10:03 rails.1 |中呈现pages / home.html.erb渲染共享/ _svg.html.erb(0.6ms)16:10:03 rails.1 |渲染共享/ _svg.html.erb(0.1ms)16:10:04 rails.1 |渲染shared / _banner_slideshow.html.erb(0.1ms)16:10:04 rails.1 |渲染共享/ _flash_messages.html.erb(0.4ms)16:10:04 rails.1 |渲染共享/ _svg.html.erb(0.1ms)16:10:04 rails.1 |渲染共享/ _svg.html.erb(0.1ms)16:10:04 rails.1 |渲染共享/ _svg.html.erb(0.1ms)16:10:04 rails.1 |渲染共享/ _svg.html.erb(0.1ms)16:10:04 rails.1 |渲染共享/ _svg.html.erb(0.1ms)16:10:04 rails.1 |在2414ms完成200 OK(浏览次数:2033.0ms | ActiveRecord:40.6ms)
为什么渲染的各个部分花费不到1毫秒,但总视图渲染时间超过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>
答案 0 :(得分:0)
您可以通过将调用减少到_flash-messages.html.erb
中的子视图来改进代码:
<% if flash.any? %>
<%= render partial: 'shared/flash_message', locals: { flash: flash } %>
<% end %>
然后在_flash-message.html.erb
:
<% flash.each do |type, message| %>
<div class="message-box message-box--<%= type %>">
<a class="close" data-dismiss="alert">×</a>
<%= message %>
</div>
<% end %>
这将减少子视图渲染,并且将花费更少的时间来完成工作。