Last active
December 28, 2024 15:12
-
-
Save johncip/17c496f04dcd032d594a785e2ad09824 to your computer and use it in GitHub Desktop.
Revisions
-
johncip revised this gist
Jun 17, 2019 . 1 changed file with 13 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,6 @@ N+1 query problem * ORMs make it easy to a query per loop iteration, which we want to avoid `eager_load` * single query (left outer join) * can reference the other table's columns in `where` @@ -13,4 +16,13 @@ `joins` * inner join * precise; allows you to *avoid* loading extra data * can use aliases to add new methods to left table's records Other AR optimizations * queries can be built without being fired (calling e.g. `all`, `first`, `count`, or `each` does that) * results of recent queries are cached * these don't help with the N+1 problem Tips * index on foreign keys * benchmark with a remote db if that's what prod uses -
johncip revised this gist
May 28, 2016 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,14 +1,14 @@ `eager_load` * single query (left outer join) * can reference the other table's columns in `where` `preload` * a few queries (one per table) * typically faster `includes` * acts like `preload` by default * falls back on `eager_load` if you reference the associated tables `joins` * inner join -
johncip revised this gist
May 28, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,7 @@ `includes` * acts like `preload` by default * acts like `eager_load` if you reference columns from associated tables `joins` * inner join -
johncip created this gist
May 28, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ `eager_load` * can reference the other table's columns in `where` * single query (left outer join) `preload` * typically faster * one query per table `includes` * acts like `preload` by default * acts like `eager_load` if you use `references` `joins` * inner join * precise; allows you to *avoid* loading extra data * can use aliases to add new methods to left table's records