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

Greg Sims created an issue. See original summary.

Wim Leers’s picture

Component: other » entity system
Category: Bug report » Support request
Status: Active » Fixed

This 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.

Greg Sims’s picture

Thanks @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.

Wim Leers’s picture

Batching 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.

Greg Sims’s picture

My 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.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.