当我甚至不打'/'时,Rails开发服务器读错了请求“开始获取'/'...”

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了当我甚至不打'/'时,Rails开发服务器读错了请求“开始获取'/'...”相关的知识,希望对你有一定的参考价值。

我正在调试我的应用程序中一个非常慢的管理页面。当我阅读日志时,似乎可能正在进行N + 1查询:

  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079887 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079805 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079744 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079910 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079875 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079898 LIMIT 1
  Unit Load (0.3ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079916 LIMIT 1
  Unit Load (0.8ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079918 LIMIT 1
  Unit Load (1.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079783 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079751 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079921 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079911 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079785 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079770 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079908 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079760 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079827 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079919 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079882 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079690 LIMIT 1
  Unit Load (0.3ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079933 LIMIT 1
  Unit Load (0.4ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079915 LIMIT 1
  Unit Load (0.6ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079707 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079906 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079892 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079801 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079913 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079900 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079947 LIMIT 1
  Unit Load (0.3ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079769 LIMIT 1
  Unit Load (0.3ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079964 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079765 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079967 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079926 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079927 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079950 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079979 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079981 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079980 LIMIT 1
  Unit Load (0.3ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079814 LIMIT 1
  Unit Load (0.9ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079931 LIMIT 1
  Unit Load (0.8ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079986 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079988 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079997 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079957 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079830 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079822 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079806 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079714 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079946 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079896 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079851 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079971 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079863 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079905 LIMIT 1
  Unit Load (0.4ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079914 LIMIT 1
  Unit Load (0.5ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079941 LIMIT 1
  Unit Load (0.3ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079848 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079953 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511080019 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079834 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079907 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079934 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079951 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511080004 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511080021 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079929 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079973 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079961 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079928 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511080027 LIMIT 1
  Unit Load (0.3ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079904 LIMIT 1
  Unit Load (0.7ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079962 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079965 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079855 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079877 LIMIT 1
  Unit Load (0.3ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079841 LIMIT 1
  Unit Load (0.3ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079816 LIMIT 1
  Unit Load (0.6ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511080040 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079932 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511080039 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079860 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511080047 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079985 LIMIT 1
  Unit Load (0.6ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079878 LIMIT 1
  Unit Load (0.9ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079826 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079945 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511080038 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079954 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511080017 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079999 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079808 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079766 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511080060 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079955 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079987 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079983 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511080008 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511080032 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511080073 LIMIT 1
  Unit Load (1.0ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079829 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511080080 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079976 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511080046 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511080003 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511080071 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079940 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079780 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511080034 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511080091 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511080072 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079695 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511080056 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079694 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079833 LIMIT 1
  Unit Load (0.1ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511080090 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511079803 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511080067 LIMIT 1
  Unit Load (0.2ms)  SELECT  `units`.* FROM `units` WHERE `units`.`id` = 511080098 LIMIT 1
  Unit Load (0.3ms)  SELECT  `units`.* FROM 

还有像这样的几十行。

当我开始调查时,我删除了视图中的所有内容以及相应的控制器操作。

的routes.rb

  # ... many other routes
  # The route causing problems  
  get '/admin/unit/:id/data/:days', to: 'admins#unit_data', as: 'unit_data'

  # You can have the root of your site routed with "root"
  root 'units#root_unit'

admins_controller.rb

def unit_data
  puts "Hello World!"
end 
...
Hello World
  Rendered admins/unit_data.html.erb within layouts/new_application (0.0ms)
  Rendered layouts/new_application.html.erb (35.0ms)
Completed 200 OK in 744ms (Views: 45.1ms | ActiveRecord: 554.4ms)

到目前为止,一切看起来都很好,它加载我的空白.erb页面,但之后,它出于某种原因请求root

Started GET "/" for ::1 at 2019-04-18 09:44:39 -0400
Processing by UnitsController#root_unit as */*

我在过滤器之前检查了一下,但是他们没有考虑到这一点。这可能是这个页面超慢的潜在原因吗?我们正在尝试优化图表上显示的大量数据......我很确定这对于极长的加载时间没有任何影响,但我仍然想要深入了解这一点。

答案

在调试单个请求时 - curl是您的朋友,因为默认情况下现代浏览器具有可以触发其他页面预测的页面预测,而您目前还没有预料到。

如果页面需要身份验证 - 您可以使用所有cookie等在devtools中“复制为cURL”,并从控制台请求页面。通过这种方式,您可以确保请求是唯一正在运行的(此时浏览器甚至可以关闭)

以上是关于当我甚至不打'/'时,Rails开发服务器读错了请求“开始获取'/'...”的主要内容,如果未能解决你的问题,请参考以下文章

'城管这次不打老百姓,还要打警察!'.html(false)

如何在'rake test'中关闭警告'ruby -w'?

运行rails应用程序时出现webpacker错误。 'TypeError:environment.plugins.set不是函数'

Rails应用程序无法在javascript中找到'destroy_user_session_path'

Rails5 + ActionCable:与'ws:// {hostname} / cable'的WebSocket连接失败:WebSocket在建立连接之前关闭

Rails Event EventType模型关联 - nil的未定义方法`title':NilClass