At PhraseApp, we provide weekly Brownbag sessions get new developers on board and share knowledge across the team. Last week, I held a Brownbag session about how to improve and debug ActiveRecord-generated SQL queries. This blog post series presents the basics of working with Rails and ActiveRecord to write a more performant code.
Today, I want to share some knowledge about improving the performance of ActiveRecord queries by selecting only the needed data and reduce the number of instantiated objects. There are many cases in your Rails application when you only need a small subset of data and not the whole record. For example, if you want to render a user select box where you only need the id” and name fields, you can use something similar to the following code:
No comments:
Post a Comment