Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7762087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:18:11+00:00 2026-06-01T14:18:11+00:00

I was reading Agile Web Development With Rails, when I saw this piece of

  • 0

I was reading Agile Web Development With Rails, when I saw this piece of code:

Order.transaction do (1..100).each do |i|
    Order.create(:name => "Customer #{i}", :address => "#{i} Main Street",
      :email => "customer-#{i}@example.com", :pay_type => "Check")
end end

The author said: “Note that this code does all this work in one transaction. This isn’t precisely required for this activity but does speed up the processing”.

So my question is, why the transaction speed up the processing of this block of code ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T14:18:13+00:00Added an answer on June 1, 2026 at 2:18 pm

    In both cases your rails apps makes 100 separate INSERT statements, but if you don’t explicitly create a transaction then each update/insert sits inside its own transaction. Transactions are supposed to be ACID, in particular the D stands for durable: once a transaction has been committed there is a hard guarantee that it has been successfully written to disk, even if a power failure occurs 1 nanosecond later.

    Committing a transaction thus requires that the writes be flushed which has an inherent cost (this can be mitigated by the right kind of RAID hardware). On the other hand when you are in the middle of one big transaction the database has no obligation to flush writes after the individual inserts.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading Pragmatic Agile Web Development with Rails (2th ed) and trying examples
OK, so I am reading Agile Web Development with Rails and working on the
I'm currently reading Agile Web Development With Rails, 3rd edition. On page 672, I
I am learning Rails the age old way. By reading Agile Web Development with
I am currently reading a book, and learning ruby on rails. (Agile Web Development
I'm reading Agile web Development to learn Rails 3.0. The author is teaching us
I started reading Agile Web Development with Rails, its a very good book! I
I'm reading the book Agile web developement with Rails 4Th editon, when he present
Reading this question I found this as (note the quotation marks) code to solve
Reading over the responses to this question Disadvantages of Test Driven Development? I got

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.