Eagerloading global images
Closed this issue · 2 comments
nkpindolia commented
I've got a global with my default seo image. globalSeo.image
I've got the Element Panel plugin installed to check when i need to eager-load stuff or I've missed it out. It keeps showing a warning when the default image is added as the seo image that the image is not eagerloaded
nkpindolia commented
adding the following code in the config seems to fix the issue:
$globalSeo = Craft::$app->globals->getSetByHandle('myGlobalHandle');
Craft::$app->elements->eagerLoadElements('\craft\elements\GlobalSet', [$globalSeo], 'seoImageHandle');
however i now get a warning: "Element query executed before Craft is fully initialized."
mmikkel commented
Eager-loading a single element makes no sense as there is no N+1 query issue. In this case, eager-loading the global set would generate additional queries, not fewer.
If you're concerned about performance, make sure that the SEOMate cache is enabled in live environments.