We've added a new field (Finalized) to an existing Node type. There are currently ~4000 nodes of this type (iproduct).

I need to be able to filter based on this new logical field, but cannot do that unless the field is populated with either a true, or false value.

If you add a new field to an existing Node type that new field does not get populated for existing Nodes and therefor does not have a default value. I wrote some code to populate the new field and resave the node, the code is executed in batches of 1000 records (to avoid timeout issues) and I've included the code for feedback. If I use the code as is the resulting Node records consume significant amount of RAM when they are loaded and I don't understand why. Note: I am not talking about during the process to update the records, but rather that after the process is complete any attempt to view the nodes causes significant memory usage.

There are 2 queries before this code, one which retrieves a node list where the field exists (and therefor populated) and the other retrieves all nodes of the type in question. I use the first result to filter the second and apply the update to only those nodes which did not have the field in the first place.

     foreach($result['node'] as $pre_node) {
       if (!empty($resultExclude['node'][$pre_node->nid])) 
         continue;
       $node = node_load($pre_node->nid,$pre_node->vid,true);
       
       if (empty($node->field_finalized)) {
         $iCount++;
         $node->field_finalized[LANGUAGE_NONE][0]['value'] = 0;
         if ($node = node_submit($node)) {
           $result = node_save($node);
         }
       }
       if ($iCount > 1000)
         return;
     }

Can anybody tell me what I am doing wrong which would cause Nodes to balloon in size or whatever is happening in this instance?

Comments

topham’s picture

I took a different approach to update the field, using Views Bulk Operations to update my Finalized field. Once the field was updated it blew up in the same manner as after my update to the field.

I've since narrowed the issue to an unexpected (for me) place, there was a Finder as a Block in the First Sidebar which had my logical field Finalized in it. When this Finder is disabled everything starts to work fine again, it looks like the version of finder I'm using has a bug that's processing a significant number of Nodes unnecessarily. (Finder 7.x-2.0-alpha8)