I want to update some term id on some node (let suppose 1000 node),My changes is convert all news node with category(term_id) = 3040 to category(term_id)=5)
.
I know I can do it with several methods( use views bulk operation, write batch running etc, .... ) but my question is about performance of below approaches
Approach based on old method ( node_save)
$query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'node') ->entityCondition('bundle', 'news') ->propertyCondition('status', 1) ->fieldCondition('field_category', 'tid', array('3040')); $result = $query->execute(); $nids= array_keys($result['node']); //ym($nids); $nodes= node_load_multiple($nids); foreach ($nodes as $node){ foreach($node->field_category['und'] as $i=>$item){ if($item['tid']==3040){ $node->field_category['und'][$i]['tid']=5; node_save($node); } } }
Approach based on entity wrapper method
$query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'node') ->entityCondition('bundle', 'news') ->propertyCondition('status', 1) ->fieldCondition('field_category', 'tid', array('3040')); $result = $query->execute(); foreach($result['node'] as $nid => $stub_node) { // Load the full node and wrap it with entity_metadata_wrapper(). $node = node_load($nid); $wrapped_node = entity_metadata_wrapper("node", $node); if ($wrapped_node->field_category->value()->tid == 3040) { $wrapped_node->field_category->tid->set(5); $wrapped_node->save(); }
in first approach we have one node_load
and one node_save
but in second approach we have one node_load
one creating entity metawrapper creation and one entity wrapper save.
I want to know which method has better performance?
let suppose we have the same situation for both 2 method, I just want somebody tell me ( take a benchmark on one node and in bulk ( multi node) mode and tell me the performance of both that which one of this method is faster in the same situation.
please provide your answer with facts or benchmark testing result