...

/

Prevention of N + 1 Requests

Prevention of N + 1 Requests

Learn how to prevent the application from generating N+1 queries.

We'll cover the following...

Include user

Imagine that we want to add the owners of the products for the path /products. We have already seen that it is straightforward to do this with the fast_jsonapi library. We will modify the code in app/controllers/api/v1/products_controller.rb:

ruby-2.6.3
Test the code using Rails test

Now, let’s request with cURL. Remember that we must obtain an authentication token before accessing the page. Click on the “Run” button to open a terminal. Then open another terminal by clicking the “++” button next to the “Terminal” tab. Initialize the rails server on the new terminal using this command:

$ cd usercode/workspace/market_place_api && rails s

Switch back to the first terminal and run:

 ...