High-performance field values changes with field_attach_update().

Public

Use field_attach_update() instead of node/entity_save

</> CopyGet raw version
php
  1. // I've used this pattern when needed to update thousands of nodes quickly without calling node_save() or entity_save().
  2. // This is much more performant than those functions because there is much less overhead. If you need the updated
  3. // field values to be in search index (e.g. Solr), you'll need to manually call the function(s) to re-index the entity.
  4.  
  5. // Set node ID.
  6. $nid = '123';
  7.  
  8. // Build a "skeleton" of the entity whose field values we need to update.
  9. $entity = new stdClass();
  10. $entity->nid = $nid;
  11. // This is node bundle/content type.
  12. $entity->type = 'article';
  13. $entity->body[LANGUAGE_NONE][0] = 'This is my node's body value.';
  14. field_attach_update('node', $entity);
  15.  
  16. // Flush this entity's cache.
  17. entity_get_controller('node')->resetCache(array($nid));