繁体   English   中英

Rails 4.2-性能问题

[英]Rails 4.2 - performance issue

我最近将我的一个应用程序更新为Rails 4.2 在本地计算机上运行时,我注意到与基本show操作的简单link_to有时需要很长时间才能完成。

链接在这里:

= link_to team_members_path(@team) do
  Members

这是我的动作(在我的MembersController ):

def index

  @team = Team.find_by_id(params[:team_id])

  if params[:search].present?
    @members = Member.search ThinkingSphinx::Query.escape(params[:search]), :with => {:team_id => @team.id}, :page => params[:page], :per_page => 10
  else
    @members = Member.search params[:search], :with => {:team_id => @team.id}, :page => params[:page], :per_page => 10
  end
end

我使用SphinxThinkingSphinx进行搜索。 单击链接时,控制台中出现异常长的“日志”。

Started GET "/users/1" for ::1 at 2014-12-24 11:24:40 +0100
Processing by UsersController#show as JS
Parameters: {"id"=>"1"}
[renders stuff etc]

...

Started GET "/users/1" for ::1 at 2014-12-24 11:24:40 +0100
Processing by UsersController#show as JS
Parameters: {"id"=>"1"}
[renders stuff etc. with the same timestamp as above]

...

Started GET "/users/1" for ::1 at 2014-12-24 11:24:40 +0100
Processing by UsersController#show as JS
Parameters: {"id"=>"1"}
[renders stuff etc. with the same timestamp as above]

这个动作: Started GET "/users/1"似乎多次被调用(比我上面粘贴的要多),即使在我的本地计算机上运行时,这似乎也会导致很差的性能。

而且我不确定如何解决它或造成它的原因。 有任何想法吗?

注意

我实际上根本不知道在这种情况下为什么要调用GET "/users/1" 我没有链接到用户显示操作。

我已经使用Firefox控制台对其进行了检查。 见下图:

在此处输入图片说明

问题似乎出在我的内联Javascript ,该Javascript具有部分形式( _form.html.haml )。 由于此表单放置在Bootstrap模态窗口中,因此可以在大多数页面上呈现,并且可以在任何地方显示。 在这一部分中,我执行一些JavascriptAjax调用。 每次呈现表单时,我都会使用Ajax执行此操作:

:javascript
  $(document).ready(function() {

  $.ajax({
    url: "#{update_idea_team_path}",
    data: {
      team_id : $('#select_idea_team').val()
    },
    dataType: "script"
  });

由于某种原因,这似乎导致了我上面的问题中描述的问题。 将Javascript和Ajax代码移动到.coffee.js文件而不是内嵌呈现,这为我解决了这个问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM