0

So I've had a read on Eager loading on CraftCMS from an article by nystudio107 and begun enhancing my website for a client but I'm currently running into an issue which I'm not sure could be fixed or its something beyond help. Here's what my situation looks like.

I have a pageBuilder Matrix field that looks something like this.

Block Types
---
cardCarousel
iconCarousel

Each of these block types has a structure where it includes a Category field called settingsPadding where content editors can select a pre-determined list of panel spacing that I've built into the build.

Here's how my content looks like for example

Item #1
---
cardCarousel
- settingsPadding: XL

Item #2
---
cardCarousel
- settingsPadding: XL

Item #3
---
iconCarousel
- settingsPadding: L

Rendering this will throw a duplicated DB query warning on the page and when I investigate the DB query mentioned, it is pointing me to the value I'm getting for settingsPadding which in my scenario above is pointing to XL.

Now, if I made the settingsPadding changes to something like this:

Item #1
---
cardCarousel
- settingsPadding: XL

Item #2
---
cardCarousel
- settingsPadding: M

Item #3
---
iconCarousel
- settingsPadding: L

Then the warning of duplicated DB query will be gone.

My guess is that CraftCMS is running the same query multiple times if the value of settingsPadding matches a different item in the page builder.

Is there a workaround for this scenario apart from changing the Field type to a Dropdown/Plain Text field?

For reference, here is how I'm using the Eager loading in my template.

<section 
  class="
    {% if topPadding is defined -%} o-panel-top--{{ topPadding.slug }} {%- endif %}  
    {% if bottomPadding is defined -%} o-panel-bottom--{{ bottomPadding.slug }} {%- endif %}
  "
>
  {# some other elements here #}
</section>
| improve this question | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.