Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

  • Blog Navigation

Hoping to improve performance, we changed a query to use the :include condition like this:

    Project.find(id, :include => :stories)

and we noticed two things:

  1. ActiveRecord decided to turn that into a LEFT OUTER JOIN. Egads! This drastically slowed things down (although we didn’t notice until several days later, when we ran a real load test with production data).
  2. acts_as_paranoid did not manage to stick it’s little “and deleted_at = nil” phrase into the query. This meant that “deleted” stories showed up when they weren’t supposed to.

So that’s two gotchas for the price of one.

In email, Nick pointed out that the joining behavior is documented and appropriate (”otherwise if there is a nil association (eg a project without any stories) you wouldn’t get a project back even though it exists!”) and Miho rejoined that AR can be dangerous because it changes what looks like beautiful, elegant Ruby into nasty, ugly, hard-to-understand SQL under the hood.

Post a Comment

Your Information (Name required. Email address will not be displayed with comment.)

* Copy This Password *

* Type Or Paste Password Here *

Share This