3

The performance of the ElementCriteriaModel for lookups is killing me.

I have 300 or so "People" entries in a craft site and trying to load them just for a basic listing page takes forever. There's just so much overhead.

In this case of i.e. a listing page, I need the entry title, slug and an image field (which I'm eager loading). I don't need all of the other fields and overhead it loads.

Is there a way to get more acceptable performance for cases like this specific one (listing page with large number of entries and limited data needed)? Or am I going to have to bypass the element criterea stuff and do the lookups myself in SQL?

Thanks

2
  • 1
    If pagination isn't an option, you'll need to bypass the ElementCriteriaModel. I ran into this recently, with Categories. Each ElementModel occupies an awful lot of memory, and there's no way to create a "partial" model from an ElementCriteriaModel query. Mar 23 '17 at 8:02
  • Unfortunately pagination isn't really an option here. Thanks Stephen.
    – JamesNZ
    Mar 26 '17 at 19:05
5

Not in Craft 2 without completely bypassing ElementCriteriaModel and building your own SQL query.

In Craft 3 (currently in beta) you can, though – you can override which columns get selected in your element queries, and you can choose whether you want the data returned as element models or just plain arrays.

{% set entries = craft.entries
    .section('news')
    .select('elements.id', 'content.title')
    .asArray()
    .all() %}
1
  • Thanks Brandon. Awesome to know that's been addressed. I'm definitely looking forward to Craft 3.
    – JamesNZ
    Mar 26 '17 at 19:10

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.