Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I'm working on a large site with hundreds of nodes.
The following caused a PHP out of memory error after consuming all available memory:
// delete all exitsing nodes
// >>> this resulted in a crash for memory use
$query = \Drupal::entityQuery('node');
$nids = $query->execute();
entity_delete_multiple('node',$nids);
The following code ran fine in the same environment:
// loop through all the d8 aliases
// >>> this ran fine.
$sql = "SELECT nid FROM {node}";
$results = db_query($sql);
if($results)
while($row = $results->fetchAssoc()) {
$nid = $row['nid'];
entity_delete_multiple('node',array($nid));
}
Perhaps there is a memory usage issue that should be addressed here.
Comments
Comment #2
Wim LeersThis is not a performance issue.
This is poorly written code. This needs to be batched. You cannot expect this to somehow be able to process 10K, 100K, 1 million or more nodes in one request. But that’s what the code implies.
Comment #3
Greg Sims CreditAttribution: Greg Sims commentedThanks @Wim Leers. I thought I might have found something interesting that needs improvement. It does seem that the "batching" could be done below the API level so that users of the API would not need to be exposed to this. It appears that I am not viewing this correctly based on your comments.
Comment #4
Wim LeersBatching means spreading across request/response-cycles.
PHP code can't do that automagically.
Imagine if we could: then the response for a HTTP request may take, for example, 20 hours. That doesn't make sense.
Comment #5
Greg Sims CreditAttribution: Greg Sims commentedMy use case is migrating content -- it starts by clearing all the existing content from the website. In this case the operation does not need to be spear across requests. It would be nice if the operation did not use all available memory.
Again, I'm trying to help here. It the issue does not have value, let's close it.
Comment #7
xjm@Greg Sims contacted me about this issue. I provided these references:
https://api.drupal.org/api/drupal/namespace/Drupal%21Core%21Queue/8
https://api.drupal.org/api/drupal/core%21includes%21form.inc/group/batch/8
#89181: Use queue API for node and comment, user, node multiple deletes