paint-brush
How To Avoid N + 1 problem in Railsby@kalavhan
139 reads

How To Avoid N + 1 problem in Rails

by Josué4mJune 30th, 2020
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

The problem occurs when we have to make a query to get each of the associations, "1" being the first query and "N" the number of queries required to get all the associations. Preload, Includes and eager_load are three ways to avoid this problem. The problem is because the queries are not handled in a proper manner this can slow down the loading, and that is because of the "N + 1" problem. If we use Preload we can't use a "where" clause in the associated table and with Includes we can fix the problem by making only two queries.

Company Mentioned

Mention Thumbnail
featured image - How To Avoid N + 1 problem in Rails
Josué HackerNoon profile picture
Josué

Josué

@kalavhan

Full stack web developer Ruby | JavaScript | PHP | CSS | RoR

About @kalavhan
LEARN MORE ABOUT @KALAVHAN'S
EXPERTISE AND PLACE ON THE INTERNET.
L O A D I N G
. . . comments & more!

About Author

Josué HackerNoon profile picture
Josué@kalavhan
Full stack web developer Ruby | JavaScript | PHP | CSS | RoR

TOPICS

THIS ARTICLE WAS FEATURED IN...

Permanent on Arweave
Read on Terminal Reader
Read this story in a terminal
 Terminal
Read this story w/o Javascript
Read this story w/o Javascript
 Lite