Hacker News new | past | comments | ask | show | jobs | submit login

As a RoR developer I have often been hired into optimize various services. One of the biggest issues I have seen is this exponential growth of queries.

I have routinely seen requests at clients with 2-3000 queries (even with query caching). Most of them are small, but at that amount it doesn't matter how small and efficient each query is.

I love AR to death as an OR library, but it is extremely easy to get into these kinds of issues when you iterate over a large dataset and then call associations of associations without thinking too much about it. I don't think it is only an AR issue, conceptually I think it is true for all ORMs.

They can be a PITA to unravel and are often very hard to do in a clean AR like way in more complex data models. Normally you end up doing some fairly un AR like pre loading like you would do in a pre ORM app, which while ugly works.




Agreed, I do all my dev with query trace in order to make sure I'm not looping back into individual queries.

to those that don't know, Rails doesn't load the children of AR objects by default, so if you do something like

Select * from books

and then iterate through the books and get books.author_name where the author data is a relational table, you're going to get a separate query for each row.


Usually the point where you could get into trouble would look more like: book.author.name in the given example.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: