Ok, so I'm looping through a lot of entries. It's a large request, and I had to up php memory limit to 512M. But I'm sure there is a less memory consuming way to do this. Also, I want to cache the whole thing, apparently 512M isn't enough for that.

Any suggestions? Should I just go ahead and use the ElementAPI?

var geojson = [
            "type": "StationCollection",
            "features": [
            {% for entry in craft.entries.section('map').limit(3000).find() %}
                "type": "Feature",
                "geometry": {
                  "type": "Point",
                  "coordinates": [
                "properties": {
                  "title": "{{entry.title}}",
                  "slug": "{{entry.slug}}",
                  "alwaysOpen": "{{entry.alwaysOpen}}",
                  "phone": "{{entry.phone}}",
                  "saturdays": "{{entry.saturdays}}",
                  "stationType": "{{entry.stationType}}",
                  "sundays": "{{entry.sundays}}",
                  "workingDays": "{{entry.workingDays}}",

            {% endfor %}

There isn't really a good way to extract large chunks of Craft entries using the core features in Twig. Every entry you fetch is a EntryModel and those take up some memory due to relations and other stuff in Yii's ActiveRecord class.

What you can do is to create your own custom Plugin that does the same thing but queries the database directly instead, by-passing Crafts EntryModels and just giving you the dataset results directly.

Here's some resources on getting started with Plugin development:

Craft official documentation: https://craftcms.com/docs/plugins/introduction

From StraightUpCraft: https://straightupcraft.com/plugin-development

A wrapper for creating a Plugin default setup: http://pluginfactory.io/

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.