N+1 queries are one of the most common performance killers in Rails apps, but also one of the easiest to fix. In this post, we'll see how a single line of code can reduce 1,101 database queries down to 3. N+1s occur in rails when you have associated ActiveRecord models, and iterate over one model while accessing fields on the…
#activerecord
5 posts
20 Nov 2025
14 Feb 2023
By: Kyler Stole Are you a car shopper but don’t know which car fits your needs? TrueCar’s Model Search can help narrow it down. It consists of a search results page (SRP) of vehicle models along with a slew of combinable filters. But what powers such a thing?? Well, Elasticsearch, because relational databases struggle with the aggregations to display counts…
7 Feb 2023
By: Kyler Stole If you ever struggle to express a query in ActiveRecord, you may be able to build it with Arel instead. Arel is the platform that manages the abstract syntax tree (AST) used to build SQL queries in Rails. It’s the implementation underneath the veneer of ActiveRecord (AR) and it’s considerably more flexible than just the functionality that…
28 Aug 2018
One of the more frequent questions people have when switching from JPA to jOOQ is how to migrate from using JPA’s first level cache? Speaking of that, are there any jOOQ guides on how to replace JPA? Any patterns on how to work without EntityManager to manage in-memory state (EM#merge()), 1st level cache, etc. — … Continue reading A Frequent…
15 Sept 2016
Microservices have been a popular topic recently. People argue over whether you should start with microservices or evolve there from a single ‘monolithic’ app . Maybe in a well designed app microservices are simply a deployment option ? It all seems rather academic when you have upward of 100,000 lines of (non-test) Ruby code glowering back at you. (And that’s…