Eager Loading Relatedto & Target Elements I have quite a substantial amount of queries heading out for this bit of code below. I've tried quite a few things to get it down, but I need to eager load some things just to try and reduce the overhead of this, but I still think it won't do enough. Is there anything I can look at to optimise this?

    {% set brandIds = craft.entries().section('brands').relatedTo({ targetElement: category }).ids() %}
    {% set offers = craft.entries().section('offers').relatedTo(brandIds).limit(6) %}

    {% for entry in offers %}
      &lt;div class="card category-card"&gt;
        &lt;a href="{{ entry.relatedBrand.one.url }}#{{ entry.id }}" title="{{ entry.title }}"&gt;
        &lt;div class="row"&gt;
          &lt;div class="col-md-12 col-4"&gt;
              {% for asset in entry.relatedBrand.one.brandLogo.all() %}
                &lt;img class="card-img-top" src="{{ asset.geturl }}" alt="Card image cap"&gt;
              {% endfor %}
          &lt;/div&gt;
          &lt;div class="col-md-12 col-8"&gt;
            &lt;div class="card-body"&gt;
              &lt;h5 class="card-title"&gt;{{ entry.title }}&lt;/h5&gt;
              &lt;p&gt;{{ entry.body }}&lt;/p&gt;
              &lt;small class="text-muted"&gt;{{ entry.relatedBrand.one }}&lt;/small&gt;
            &lt;/div&gt;
          &lt;/div&gt;
          &lt;/div&gt;
        &lt;/a&gt;
      &lt;/div&gt;
  {% endfor %}
First of all just a few ideas about best practices

Don't

{{ entry.relatedBrand.one.url }}
{{ entry.relatedBrand.one.title }}
{{ entry.relatedBrand.one.size }}


Do

{% set relatedImage = entry.relatedBrand.one() %}
{{ relatedImage.url }}
{{ relatedImage.title }}
{{ relatedImage.size }}


Furthermore your code with eager loading

{% set brandIds = craft
    .entries()
    .section('brands')
    .relatedTo({ targetElement: category })
    .ids() 
%}
{% set offers = craft
    .entries()
    .section('offers')
    .with(['relatedBrand.brandLogo'])
    .relatedTo(brandIds)
    .limit(6) 
    .all()
%}

{% for entry in offers %}
  &lt;div class="card category-card"&gt;
    {% set relatedBrand = entry.relatedBrand? entry.relatedBrand[0] : null %}
    &lt;a href="{{ relatedBrand.url?? '' }}#{{ entry.id }}" title="{{ entry.title }}"&gt;
    &lt;div class="row"&gt;
      &lt;div class="col-md-12 col-4"&gt;
          {% set logos = relatedBrand? relatedBrand.brandLogo : [] %}
          {% for asset in logos %}
            &lt;img class="card-img-top" src="{{ asset.geturl }}" alt="Card image cap"&gt;
          {% endfor %}
      &lt;/div&gt;
      &lt;div class="col-md-12 col-8"&gt;
        &lt;div class="card-body"&gt;
          &lt;h5 class="card-title"&gt;{{ entry.title }}&lt;/h5&gt;
          &lt;p&gt;{{ entry.body }}&lt;/p&gt;
          &lt;small class="text-muted"&gt;{{ relatedBrand.title?? '' }}&lt;/small&gt;
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;/div&gt;
    &lt;/a&gt;
  &lt;/div&gt;
{% endfor %}