Timeline for Understanding Eager Loading
Current License: CC BY-SA 3.0
12 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Nov 10, 2016 at 20:12 | history | edited | Mats Mikkel Rummelhoff | CC BY-SA 3.0 |
added 13 characters in body
|
Nov 10, 2016 at 20:05 | comment | added | Mats Mikkel Rummelhoff | Regarding the error, there was a typo in the docs where I lifted the example from. Updated my answer. | |
Nov 10, 2016 at 20:04 | history | edited | Mats Mikkel Rummelhoff | CC BY-SA 3.0 |
added 13 characters in body
|
Nov 10, 2016 at 16:20 | comment | added | Terry Upton | Let us continue this discussion in chat. | |
Nov 10, 2016 at 15:27 | comment | added | Terry Upton | The error is Craft\EntryModel and its behaviors do not have a method or closure named "bannerImage". | |
Nov 9, 2016 at 22:53 | comment | added | Mats Mikkel Rummelhoff | Also, the first example in my answer was basically lifted straight from the docs – what was the error? | |
Nov 9, 2016 at 22:50 | comment | added | Mats Mikkel Rummelhoff |
Let's say you have a template with 4 separate queries (e.g. craft.entries or craft.categories etc), where each query returns only a small number of elements (e.g. 5 entries, 3 categories) with relational data; you're not going to see a huge improvement with eager loading. Eager loading is really only very effective when a single query results in large number of additional queries (e.g. a query that returns a set of 100 entries, each with 3 different relational fields – that would amount to 301 queries in total using lazy loading, but could be reduced to 1 query with eager loading).
|
|
Nov 9, 2016 at 22:18 | comment | added | Terry Upton | Thanks. I will have another look through my code as to why this wasn't working correctly. I tried on Slack but didn't get much input. The first suggestion in your answer I was getting errors, the second more comprehensive approach, worked (no errors) but I can't recall how effective it was. I am only calling three related cards. So might not impact really. I will take another look. Thanks. | |
Nov 9, 2016 at 19:21 | comment | added | Mats Mikkel Rummelhoff | For more info, see the official docs or Straight Up Craft. There's probably more resources out there, and you could also tune into the official Slack channel to discuss the subject further and/or get more help. | |
Nov 9, 2016 at 19:19 | comment | added | Mats Mikkel Rummelhoff | The general rule is "whenever you need to avoid the N+1 query problem". 77 queries isn't actually a huge number and eager loading isn't a silver bullet, but it can be very effective. Without seeing your complete template its impossible to say if eager loading will make a big difference in your particular case, but if the number of queries doesn't go down at all its likely that your implementation is still off. | |
Nov 9, 2016 at 15:48 | comment | added | Terry Upton | Thanks for this Mats. Is there a general guide as to when you should really use Eager loading? I am not seeing much improvement. Perhaps my implementation isn't 100%. I currently have 77 queries for the whole page. This includes a matrix block, 4 related product, 3 related articles (cards), and three related articles (titles and dates). | |
Nov 8, 2016 at 21:58 | history | answered | Mats Mikkel Rummelhoff | CC BY-SA 3.0 |