Skip to content
Snippets Groups Projects
Commit 1e830175 authored by catch's avatar catch
Browse files

Issue #3260276 by arunkumark, jasonawant, ravi.shankar, TomTech, quietone,...

Issue #3260276 by arunkumark, jasonawant, ravi.shankar, TomTech, quietone, danflanagan8, catch, mikelutz, alexpott: Add static cache to Migration FieldableEntity::getFields
parent 485e4942
No related branches found
No related tags found
No related merge requests found
...@@ -20,6 +20,13 @@ ...@@ -20,6 +20,13 @@
*/ */
abstract class FieldableEntity extends 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. * Returns all non-deleted field instances attached to a specific entity type.
* *
...@@ -38,18 +45,23 @@ abstract class FieldableEntity extends DrupalSqlBase { ...@@ -38,18 +45,23 @@ abstract class FieldableEntity extends DrupalSqlBase {
* The field instances, keyed by field name. * The field instances, keyed by field name.
*/ */
protected function getFields($entity_type, $bundle = NULL) { protected function getFields($entity_type, $bundle = NULL) {
$query = $this->select('field_config_instance', 'fci') $cid = $entity_type . ':' . ($bundle ?? '');
->fields('fci') if (!isset($this->fieldInfo[$cid])) {
->condition('fci.entity_type', $entity_type) $query = $this->select('field_config_instance', 'fci')
->condition('fci.bundle', $bundle ?? $entity_type) ->fields('fci')
->condition('fci.deleted', 0); ->condition('fci.entity_type', $entity_type)
->condition('fci.bundle', $bundle ?? $entity_type)
->condition('fci.deleted', 0);
// Join the 'field_config' table and add the 'translatable' setting to the
// query.
$query->leftJoin('field_config', 'fc', '[fci].[field_id] = [fc].[id]');
$query->addField('fc', 'translatable');
// Join the 'field_config' table and add the 'translatable' setting to the $this->fieldInfo[$cid] = $query->execute()->fetchAllAssoc('field_name');
// query. }
$query->leftJoin('field_config', 'fc', '[fci].[field_id] = [fc].[id]');
$query->addField('fc', 'translatable');
return $query->execute()->fetchAllAssoc('field_name'); return $this->fieldInfo[$cid];
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment