1

What I'm doing is fairly simple:

{% cache %}
    {% set jobs = craft.entries.section('job').find({ order: 'dateCreated asc', limit: 0 }) %}
    {% for job in jobs %}
        {{ macros.jobProfile(job) }}
    {% endfor %}
{% endcache %}

... where the macro simply renders a block with a couple of things in it. I need to display all 200 entries I have, but Craft usually times out on that query (128MB RAM set).

Is there a way to tell Craft to not fetch all fields of that query, so I can optimize it directly at that point? I believe I have some content blocks in there, which probably go into RAM and eat it up, but are not needed at that time.

Any other recommendations are highly welcome. (I don't wanna write a plugin, or paginate at this point.)

Update:

{% macro jobProfile(job) %}

    {% import _self as macros %}

    <div>
        {% cache %}
            {% set attributes = job.jobProfileAttributes %}
            {% set attributeStr = "" %}
            {% set counter = 0 %}
            {% for attr in attributes %}
                {% if counter == 0 %}
                    {% set attributeStr = attr.slug%}
                {% else %}
                    {% set attributeStr = attributeStr ~" " ~attr.slug%}
                {% endif %}

                {% set counter = counter + 1 %}
            {% endfor %}

            <div style="background-image: url({{ macros.renderImageUrl(job.jobProfileImage, 'teaser1') }})"
                data-jobProfileAttributes="{{ attributeStr }}">
                <a class="teaserLink" href="{{ url(job.uri) }}">
                    <h4>{{ job.jobProfileDesignation|raw }}</h4>
                </a>
            </div>

        {% endcache %}

    </div>

{% endmacro %}
  • What makes you think it's the selected fields that is eating the memory? If you know you only need 200, try setting the limit to 200? Can you post the macro? It might be doing something memory intensive as well. – Brad Bell Jul 13 '15 at 6:32
  • Yeah you shouldn't run out of RAM fetching 200 entries. Try {% set jobs = craft.entries.section('job').order('dateCreated asc').limit(200) %} – darylknight Jul 13 '15 at 11:05
  • but uhm....when i only have arround 200 entries..limit 200....wont do much difference then what i have now...im rendering all out...which is....200 :) – nexflo Jul 13 '15 at 13:44
  • 1
    Could it be the cache wrapping the 200 other caches? And I'm not seeing the use for two for loops for jobs? You can remove the outer one at least? The one in the template, not the macro? – megatrond Jul 13 '15 at 14:09
  • 1
    Like @megatrond I'm confused by what you are passing to jobProfile. A single job? Or multiple jobs? – Marion Newlevant Jul 13 '15 at 17:42

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.