Issue #3260276 by arunkumark, jasonawant, ravi.shankar, TomTech, quietone, danflanagan8, catch, mikelutz, alexpott: Add static cache to Migration FieldableEntity::getFields

merge-requests/4726/head
catch 2023-09-07 22:56:30 +01:00
parent 485e4942c2
commit 1e83017587
1 changed files with 22 additions and 10 deletions

View File

@ -20,6 +20,13 @@ use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
*/
abstract class FieldableEntity extends DrupalSqlBase {
/**
* Cached field and field instance definitions.
*
* @var array
*/
protected $fieldInfo;
/**
* Returns all non-deleted field instances attached to a specific entity type.
*
@ -38,6 +45,8 @@ abstract class FieldableEntity extends DrupalSqlBase {
* The field instances, keyed by field name.
*/
protected function getFields($entity_type, $bundle = NULL) {
$cid = $entity_type . ':' . ($bundle ?? '');
if (!isset($this->fieldInfo[$cid])) {
$query = $this->select('field_config_instance', 'fci')
->fields('fci')
->condition('fci.entity_type', $entity_type)
@ -49,7 +58,10 @@ abstract class FieldableEntity extends DrupalSqlBase {
$query->leftJoin('field_config', 'fc', '[fci].[field_id] = [fc].[id]');
$query->addField('fc', 'translatable');
return $query->execute()->fetchAllAssoc('field_name');
$this->fieldInfo[$cid] = $query->execute()->fetchAllAssoc('field_name');
}
return $this->fieldInfo[$cid];
}
/**