1

I'm checking Element API's performance to decide if it's a good idea to replace my own custom API with Element API. Right now, when fetching the related items (Via fields or matrix elements), my API creates a unique joined query with all the right criteria and executes it at the end.

As Element API is able to use all the nice methods from Craft, maybe the question is related to Craft structure itself.

I've tried using MySQL´s SHOW STATUS LIKE 'Com_Select' but it was not really useful.

  • 2
    You know you can include a with parameter to all ElementQueriesin order to eager load the elements, thus you'll only have one single query for all elements and all related elements instead of multiple? – Robin Schambach May 15 '18 at 11:27
2

As Robin mentioned in a comment, this is exactly what eager loading was designed for... bringing in related elements in a single element query call.

The above link shows how to do it from Twig, but you can do it from PHP as well: https://straightupcraft.com/articles/examples-of-eager-loading-elements-in-twig-and-php

| improve this answer | |

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.