This is not the document you are looking for? Use the search form below to find more!

Report home > Others

How to avoid hanging yourself with Rails

0.00 (0 votes)
Document Description
How to avoid hanging yourself with Rails
File Details
Submitter
  • Name: eliasz

We are unable to create an online viewer for this document. Please download the document instead.

How to avoid hanging yourself with Rails screenshot

Add New Comment




Related Documents

How To Get Pregnant Fast With Irregular Periods

by: regina, 5 pages

How To Get Pregnant Fast With Irregular Periods

How to Avoid College Debt

by: ScottC, 2 pages

The article “How to Avoid College Debt” highlights important factors which should be considered for frugal financial planning for college. It also educates students about financial aid ...

Secrets How to make $1800-month with CPALead

by: neo61322, 4 pages

Secrets How to make $1800-month with CPALead

Secrets How to make $2000 month with CPALead

by: neo61322, 4 pages

Secrets How to make $2000 month with CPALead

Secret behind Dating Websites. How to avoid bots and spammers

by: G0dF4ther, 1 pages

How to avoid bots and spammers on dating websites and actually speak to genuine people!

How To Make Small Talk With Strangers

by: tomas, 19 pages

How To Make Small Talk with Strangers: 3 Conversation Tips That Work Like A Charm Michael Lee http://www.20daypersuasion.com/secrets.htm If you want to know how to make ...

How to do Long Division with Remainders

by: math_edutireteam, 3 pages

including the variable and the variables raised the power and multiply the variable by its coefficient. Polynomial which have one variable is a simplest polynomial. It has many form of degree ...

How-To-Avoid-Jet-Lag-26

by: befterriager817, 9 pages

locate Fortunately, this report includes the latest how to avoid jet lag info

How to Be Massively Successful with Women

by: mastermind247, 9 pages

4 Breakthroughs That Will Revolutionize Your Love Life and Your Lays

Content Preview
work.rowanhick.comHow to avoid hanging yourself with RailsUsing ActiveRecord right the first time1Discussion tonight• Intended for new Rails Developers• People that think Rails is slow• Focus on simple steps to improve common :has_many performance problems• Short - 15mins• All links/references up on http://work.rowanhick.com tomorrow2About me• New Zealander (not Australian)• Product Development Mgr for a startup in Toronto• Full time with Rails for 2 years• Previously PHP/MySQL for 4 years• 6 years Prior QA/BA/PM for Enterprise CAD/CAM software dev company3Disclaimer• For sake of brevity and understanding, the SQL shown here is cut down to “psuedo sql”• This is not an exhaustive in-depth analysis, just meant as a heads up• Times were done using ApacheBench through mongrel in production mode• ab -n 1000 http://127.0.0.1/orders/test_xxxx 4ActiveRecord lets you get in trouble far to quick. • Super easy syntax comes at a cost. @orders = Order.find(:all)@orders.each do |order| puts order.customer.name puts order.customer.country.nameend✴Congratulations, you just overloaded your DB with (total number of Orders x 2) unnecessary SQL calls5What happened there?• One query to get the orders@orders = Order.find(:all)“SELECT * FROM orders” • For every item in the orders collection customer.name:“SELECT * FROM customers WHERE id = x”customer.country.name:“SELECT * FROM customers WHERE id = y”6Systemic Problem in Web developmentI’ve seen:- 15 Second page reloads - 10000 queries per page“<insert name here> language performs really poorly, we’re going to get it redeveloped in <insert new language here>”7Atypical root cause• Failure to build application with *real* data• ie “It worked fine on my machine” but the developer never loaded up 100’000 records to see what would happen• Using Rake tasks to build realistic data sets• Test, test, test• tail -f log/development.log8Faker to the rescue• in lib/xchain.rake namespace :xchain do desc "Load fake customers" task :load_customers => :environment do require 'Faker' Customer.find(:all, :conditions => "email LIKE('%XCHAIN_%')").each { |c| c.destroy } 1..300.times do c = Customer.new c.status_id = rand(3) + 1 c.country_id = rand(243) + 1 c.name = Faker::Company.name c.alternate_name = Faker::Company.name c.phone = Faker::PhoneNumber.phone_number c.email = "XCHAIN_"+Faker::Internet.email c.save end end$ rake xchain:load_customers9Eager loading• By using :include in .finds you create sql joins• Pull all required records in one queryfind(:all, :include => [ :customer, :order_lines ])✓ order.customer, order.order_linesfind(:all, :include => [ { :customer => :country }, :order_lines ])✓ order.customer order.customer.country order.order_lines10

Download
How to avoid hanging yourself with Rails

 

 

Your download will begin in a moment.
If it doesn't, click here to try again.

Share How to avoid hanging yourself with Rails to:

Insert your wordpress URL:

example:

http://myblog.wordpress.com/
or
http://myblog.com/

Share How to avoid hanging yourself with Rails as:

From:

To:

Share How to avoid hanging yourself with Rails.

Enter two words as shown below. If you cannot read the words, click the refresh icon.

loading

Share How to avoid hanging yourself with Rails as:

Copy html code above and paste to your web page.

loading