Commit 0df5b37a authored by Dries's avatar Dries
Browse files

- Patch #729186 by catch: _field_info_collate_fields() resource usage.

parent ef1fd488
......@@ -186,47 +186,46 @@ function _field_info_collate_fields($reset = FALSE) {
if (!isset($info)) {
if ($cached = cache_get('field_info_fields', 'cache_field')) {
$definitions = $cached->data;
$info = $cached->data;
}
else {
$definitions = array(
'field_ids' => field_read_fields(array(), array('include_deleted' => 1)),
'instances' => field_read_instances(),
);
cache_set('field_info_fields', $definitions, 'cache_field');
}
// Populate 'field_ids' with all fields.
$info['field_ids'] = array();
foreach ($definitions['field_ids'] as $key => $field) {
$info['field_ids'][$key] = $definitions['field_ids'][$key] = _field_info_prepare_field($field);
}
// Populate 'fields' with all fields, keyed by ID.
$info['fields'] = array();
foreach ($definitions['field_ids'] as $key => $field) {
$info['fields'][$key] = $definitions['field_ids'][$key] = _field_info_prepare_field($field);
}
// Populate 'fields' only with non-deleted fields.
$info['fields'] = array();
foreach ($info['field_ids'] as $field) {
if (!$field['deleted']) {
$info['fields'][$field['field_name']] = $field;
// Build an array of field IDs for non-deleted fields, keyed by name.
$info['field_ids'] = array();
foreach ($info['fields'] as $key => $field) {
if (!$field['deleted']) {
$info['field_ids'][$field['field_name']] = $key;
}
}
}
// Populate 'instances'. Only non-deleted instances are considered.
$info['instances'] = array();
foreach (field_info_bundles() as $entity_type => $bundles) {
foreach ($bundles as $bundle => $bundle_info) {
$info['instances'][$entity_type][$bundle] = array();
// Populate 'instances'. Only non-deleted instances are considered.
$info['instances'] = array();
foreach (field_info_bundles() as $entity_type => $bundles) {
foreach ($bundles as $bundle => $bundle_info) {
$info['instances'][$entity_type][$bundle] = array();
}
}
}
foreach ($definitions['instances'] as $instance) {
$field = $info['fields'][$instance['field_name']];
$instance = _field_info_prepare_instance($instance, $field);
$info['instances'][$instance['entity_type']][$instance['bundle']][$instance['field_name']] = $instance;
// Enrich field definitions with the list of bundles where they have
// instances. NOTE: Deleted fields in $info['field_ids'] are not
// enriched because all of their instances are deleted, too, and
// are thus not in $definitions['instances'].
$info['fields'][$instance['field_name']]['bundles'][$instance['entity_type']][] = $instance['bundle'];
$info['field_ids'][$instance['field_id']]['bundles'][$instance['entity_type']][] = $instance['bundle'];
foreach ($definitions['instances'] as $instance) {
$field = $info['fields'][$instance['field_id']];
$instance = _field_info_prepare_instance($instance, $field);
$info['instances'][$instance['entity_type']][$instance['bundle']][$instance['field_name']] = $instance;
// Enrich field definitions with the list of bundles where they have
// instances. NOTE: Deleted fields in $info['field_ids'] are not
// enriched because all of their instances are deleted, too, and
// are thus not in $definitions['instances'].
$info['fields'][$instance['field_id']]['bundles'][$instance['entity_type']][] = $instance['bundle'];
}
cache_set('field_info_fields', $info, 'cache_field');
}
}
......@@ -525,7 +524,12 @@ function field_info_bundles($entity_type = NULL) {
*/
function field_info_fields() {
$info = _field_info_collate_fields();
return $info['fields'];
foreach ($info['fields'] as $key => $field) {
if (!$field['deleted']) {
$fields[$field['field_name']] = $field;
}
}
return $fields;
}
/**
......@@ -544,8 +548,8 @@ function field_info_fields() {
*/
function field_info_field($field_name) {
$info = _field_info_collate_fields();
if (isset($info['fields'][$field_name])) {
return $info['fields'][$field_name];
if (isset($info['field_ids'][$field_name])) {
return $info['fields'][$info['field_ids'][$field_name]];
}
}
......@@ -565,8 +569,8 @@ function field_info_field($field_name) {
*/
function field_info_field_by_id($field_id) {
$info = _field_info_collate_fields();
if (isset($info['field_ids'][$field_id])) {
return $info['field_ids'][$field_id];
if (isset($info['fields'][$field_id])) {
return $info['fields'][$field_id];
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment