Disclaimer. Those who are not familiarized with N+1 problem, you can check “What is the N+1 selects problem in ORM(Object-Relational Mapping) with details explaining the concept.
Since associations were introduced in Pop, the N+1 problem became part of it: many queries hit the database in order to load whole model’s associations. Good news is N+1 problem is not a disease without remedy. In this post I will give you some steps I took to solve it by incorporating emergent design.
Step 1: Start Coding By Example
Coding by example helps you to define what’s your input and what’s your output. Code By Example means you define a scenario where your solution is tested and what is the expected result. The method I used to apply this technique was Test Driven Development (TDD).