Rendering Performance when populating Nested Form - Rails 4 - OmniContacts -


in app using omnicontacts gem allow users import contacts. works. getting contacts gmail takes 300-500ms.

in order allow importing of contacts putting them in nested form. rendering of each contact takes 175-300ms, multiply 1000 , crappy.

i love there rails solution issue. otherwise guessing using ajax , js form might work. thoughts , time appreciated.

import controller:

  def import     @user = current_user     @import = request.env['omnicontacts.contacts']     @contacts = @import.map |contact_info|       contact.new(         first_name: contact_info[:first_name],         last_name:  contact_info[:last_name],         email_home: contact_info[:email],         phone_home: contact_info[:phone]       )     end      respond_to |format|       format.html     end   end 

import view:

<div class="row">   <div class="small-12">     <%= simple_form_for(@user, url: import_path) |f| %>         <%= f.simple_fields_for :contacts, @contacts |contact| %>             <%= render 'contact_fields', f: contact %>         <% end %>         <div class="actions" align="right">           <%= f.submit class:"button tiny" %>         </div>     <% end %>   </div> </div> 

nested form partial:

<div class='nested-fields'>   <fieldset>   <div class="row">     <div class="small-2 columns">       <%= f.input :import, as: :boolean %>     </div>     <div class="small-2 columns">       <%= f.input :first_name %>     </div>     <div class="small-2 columns">       <%= f.input :last_name %>     </div>     <div class="small-4 columns">       <%= f.input :email_home %>     </div>     <div class="small-2 columns">       <%= f.input :phone_home %>     </div>   </div>   </fieldset> </div> 

log of doom: (close eyes , imagine 1000+ rendered lines added)

started "/oauth2callback?code=4/xzhdnpj8rgrb7sfstq3tvm-ff2q5wolrvhtsoki0egg" ::1 @ 2015-06-18 12:16:09 -0500 processing importscontroller#import html   parameters: {"code"=>"4/xzhdnpj8rgrb7sfstq3tvm-ff2q5wolrvhtsoki0egg"}   user load (0.5ms)  select  "users".* "users" "users"."id" = $1  order "users"."id" asc limit 1  [["id", 1]]   rendered imports/_contact_fields.html.erb (301.0ms)   rendered imports/_contact_fields.html.erb (233.9ms)   rendered imports/_contact_fields.html.erb (276.8ms)   rendered imports/_contact_fields.html.erb (180.3ms)   rendered imports/import.html.erb within layouts/application (1001.0ms)   rendered layouts/_header.html.erb (2.8ms)   rendered layouts/_footer.html.erb (3.8ms) completed 200 ok in 1548ms (views: 1540.0ms | activerecord: 0.5ms) 

turns out issue simple form. changed form partial to:

<div class='nested-fields'>   <fieldset>   <div class="row">     <div class="small-1 columns">       <%= f.label "import" %>       <%= f.check_box :import %>     </div>     <div class="small-2 columns">       <%= f.label :firs_name %>       <%= f.text_field :first_name %>     </div>     <div class="small-2 columns">       <%= f.label :last_name %>       <%= f.text_field :last_name %>     </div>     <div class="small-4 columns">       <%= f.label :email_home %>       <%= f.text_field :email_home %>     </div>     <div class="small-3 columns">       <%= f.label :phone_home %>       <%= f.text_field :phone_home %>     </div>   </div>   </fieldset> </div> 

performance increased:

  rendered imports/_contact_fields.html.erb (43.5ms)   rendered imports/_contact_fields.html.erb (1.0ms)   rendered imports/_contact_fields.html.erb (0.7ms)   rendered imports/_contact_fields.html.erb (0.7ms)   rendered imports/import.html.erb within layouts/application (407.4ms) 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -