1

I have a view which uses search_api (and solr) to get a list of nodes, and then displays selected fields, including some from a relationship to commerce_product

This is resulting in about a thousand database queries to display about 20 nodes, which I think is inefficient.

Digging in further, it looks like search_api returns a list of nids, which are then loaded with a single invocation of entity_load (which causes several DB queries as field_attach_load loads each of the bundle's fields in turn, loading values for all nodes at once)

But when it comes to the commerce_products in the relationship, these are loaded one-by-one somewhere during the field render process, rather than all in one go. So the total number of queries is close to (number of results) x (number of fields) instead of just (number of fields) like it would be without the relationship.

(Yes, I have quite a few fields)

Is there any way I can get Views to load all of the referenced entities in one go, rather than in this inefficient one-by-one manner?

screenshot of views UI

1

Is there any way get Views to load all of the referenced entities in one go? No, there's not much you can easily change to fix that.

There's a lot of behaviour built in so that Drupal can handle multilingual data or different data storage back ends like MongoDB.

If you're not already doing so, you can use entitycache module to lighten the load. For cached entities, you will eliminate a lot of queries.

FYI, Entitycache will not work on its own. You will need to integrate with a cache back end like Redis or Memcache. See the module documentation and READMEs for configuration details.

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.