Commit 1d48f07f authored by Dries's avatar Dries

- Patch #869350 by chx, yched: some field functions are called a bit too often.

parent d58e32ed
......@@ -1522,11 +1522,12 @@ function hook_field_storage_details_alter(&$details, $field) {
* loaded.
*/
function hook_field_storage_load($entity_type, &$entities, $age, $fields, $options) {
$field_info = field_info_field_by_ids();
$etid = _field_sql_storage_etid($entity_type);
$load_current = $age == FIELD_LOAD_CURRENT;
foreach ($fields as $field_id => $ids) {
$field = field_info_field_by_id($field_id);
$field = $field_info[$field_id];
$field_name = $field['field_name'];
$table = $load_current ? _field_sql_storage_tablename($field) : _field_sql_storage_revision_tablename($field);
......
......@@ -273,6 +273,7 @@ function _field_invoke_multiple($op, $entity_type, $entities, &$a = NULL, &$b =
'language' => NULL,
);
$options += $default_options;
$field_info = field_info_field_by_ids();
$fields = array();
$grouped_instances = array();
......@@ -296,7 +297,7 @@ function _field_invoke_multiple($op, $entity_type, $entities, &$a = NULL, &$b =
foreach ($instances as $instance) {
$field_id = $instance['field_id'];
$field_name = $instance['field_name'];
$field = field_info_field_by_id($field_id);
$field = $field_info[$field_id];
$function = $options['default'] ? 'field_default_' . $op : $field['module'] . '_field_' . $op;
if (function_exists($function)) {
// Add the field to the list of fields to invoke the hook on.
......@@ -583,6 +584,7 @@ function field_attach_form($entity_type, $entity, &$form, &$form_state, $langcod
* non-deleted fields are operated on.
*/
function field_attach_load($entity_type, $entities, $age = FIELD_LOAD_CURRENT, $options = array()) {
$field_info = field_info_field_by_ids();
$load_current = $age == FIELD_LOAD_CURRENT;
// Merge default options.
......@@ -660,7 +662,7 @@ function field_attach_load($entity_type, $entities, $age = FIELD_LOAD_CURRENT, $
}
// Collect the storage backend if the field has not been loaded yet.
if (!isset($skip_fields[$field_id])) {
$field = field_info_field_by_id($field_id);
$field = $field_info[$field_id];
$storages[$field['storage']['type']][$field_id][] = $load_current ? $id : $vid;
}
}
......
......@@ -575,6 +575,25 @@ function field_info_field_by_id($field_id) {
}
}
/**
* Returns the same data as field_info_field_by_id() for every field.
*
* This function is typically used when handling all fields of some entities
* to avoid thousands of calls to field_info_field_by_id().
*
* @return
* An array, each key is a field ID and the values are field arrays as
* returned by field_read_fields(), with an additional element 'bundles',
* whose value is an array of all the bundle this field belongs to.
*
* @see field_info_field()
* @see field_info_field_by_id()
*/
function field_info_field_by_ids() {
$info = _field_info_collate_fields();
return $info['fields'];
}
/**
* Retrieves information about field instances.
*
......
......@@ -309,11 +309,12 @@ function field_sql_storage_field_storage_delete_field($field) {
* Implements hook_field_storage_load().
*/
function field_sql_storage_field_storage_load($entity_type, $entities, $age, $fields, $options) {
$field_info = field_info_field_by_ids();
$etid = _field_sql_storage_etid($entity_type);
$load_current = $age == FIELD_LOAD_CURRENT;
foreach ($fields as $field_id => $ids) {
$field = field_info_field_by_id($field_id);
$field = $field_info[$field_id];
$field_name = $field['field_name'];
$table = $load_current ? _field_sql_storage_tablename($field) : _field_sql_storage_revision_tablename($field);
......
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