diff -u b/core/modules/field/field.purge.inc b/core/modules/field/field.purge.inc --- b/core/modules/field/field.purge.inc +++ b/core/modules/field/field.purge.inc @@ -111,6 +111,11 @@ $ids->entity_id = $entity_id; $entity = _field_create_entity_from_ids($ids); \Drupal::entityManager()->getStorage($entity_type)->onFieldItemsPurge($entity, $instance); + $batch_size--; + } + // Only delete up to the maximum number of records. + if ($batch_size == 0) { + break; } } else { @@ -123,6 +128,10 @@ $deleted_fields = \Drupal::state()->get('field.field.deleted') ?: array(); foreach ($deleted_fields as $field) { $field = new FieldConfig($field); + if ($field_uuid && $field->uuid() != $field_uuid) { + // If a specific UUID provided only operate on that UUID. + continue; + } // We cannot purge anything if the entity type is unknown (e.g. the // providing module was uninstalled). diff -u b/core/modules/field/lib/Drupal/field/ConfigImporterFieldPurger.php b/core/modules/field/lib/Drupal/field/ConfigImporterFieldPurger.php --- b/core/modules/field/lib/Drupal/field/ConfigImporterFieldPurger.php +++ b/core/modules/field/lib/Drupal/field/ConfigImporterFieldPurger.php @@ -72,12 +72,12 @@ // There will be one step to delete the instances and field. $context['sandbox']['field']['steps_to_delete'] = count($fields); foreach ($fields as $field) { - $row_count = $field->numberOfRows(); + $row_count = $field->entityCount(); if ($row_count > 0) { // The number of steps to delete each field is determined by the // purge_batch_size setting. For example if the field has 9 rows and the // batch size is 10 then this will add 1 step to $number_of_steps. - $how_many_steps = (int) ($row_count / $context['sandbox']['field']['purge_batch_size']) + 1; + $how_many_steps = ceil($row_count / $context['sandbox']['field']['purge_batch_size']); $context['sandbox']['field']['steps_to_delete'] += $how_many_steps; } } reverted: --- b/core/modules/field/lib/Drupal/field/Entity/FieldConfig.php +++ a/core/modules/field/lib/Drupal/field/Entity/FieldConfig.php @@ -660,57 +660,32 @@ * TRUE if the field has data for any entity; FALSE otherwise. */ public function hasData() { + if ($this->getBundles()) { - return (bool) $this->numberOfRows(TRUE); - } - - /** - * Determines the number of rows of data this field has. - * - * @param bool $has_data - * (Optional) Optimises query for hasData(). - * - * @return int - * The number of rows of data for this field. If $has_data parameter is TRUE - * then the value will either be 0 or 1. - */ - public function numberOfRows($has_data = FALSE) { - $factory = \Drupal::service('entity.query'); - $entity_type = \Drupal::entityManager()->getDefinition($this->entity_type); - // Entity Query throws an exception if there is no base table. - if (!$entity_type->getBaseTable()) { - return 0; - } - - if ($this->deleted) { - $query = $factory->get($this->entity_type) - ->condition('id:' . $this->uuid() . '.deleted', 1) - ->count() - ->accessCheck(FALSE); - } - elseif ($this->getBundles()) { $storage_details = $this->getSchema(); $columns = array_keys($storage_details['columns']); + $factory = \Drupal::service('entity.query'); + // Entity Query throws an exception if there is no base table. + $entity_type = \Drupal::entityManager()->getDefinition($this->entity_type); + if (!$entity_type->getBaseTable()) { + return FALSE; + } - $query = $factory->get($this->entity_type); $group = $query->orConditionGroup(); foreach ($columns as $column) { $group->exists($this->name . '.' . $column); } + $result = $query - $query = $query ->condition($group) ->count() + ->accessCheck(FALSE) + ->range(0, 1) + ->execute(); + if ($result) { + return TRUE; + } - ->accessCheck(FALSE); } + return FALSE; - if (isset($query)) { - // If we are performing the query just to check if the field has data - // limit the number of rows returned by the subquery. - if ($has_data) { - $query->range(0, 1); - } - return (int) $query->execute(); - } - return 0; } /**