Commit de8761eb authored by Dries's avatar Dries
Browse files

- Patch #721436 by chx, moshe weitzman: improved performance of user_save() by...

- Patch #721436 by chx, moshe weitzman: improved performance of user_save() by removing and reworking some code.
parent 5f4dd61f
...@@ -360,16 +360,9 @@ function user_save($account, $edit = array(), $category = 'account') { ...@@ -360,16 +360,9 @@ function user_save($account, $edit = array(), $category = 'account') {
unset($edit['pass']); unset($edit['pass']);
} }
// Get the fields form so we can recognize the fields in the $edit // Presave field allowing changing of $edit.
// form that should not go into the serialized data array.
$field_form = array();
$field_form_state = form_state_defaults();
$edit = (object) $edit; $edit = (object) $edit;
field_attach_form('user', $edit, $field_form, $field_form_state);
// Presave fields.
field_attach_presave('user', $edit); field_attach_presave('user', $edit);
$edit = (array) $edit; $edit = (array) $edit;
if (!isset($account->is_new)) { if (!isset($account->is_new)) {
...@@ -385,11 +378,19 @@ function user_save($account, $edit = array(), $category = 'account') { ...@@ -385,11 +378,19 @@ function user_save($account, $edit = array(), $category = 'account') {
if (empty($edit['access']) && empty($account->access) && user_access('administer users')) { if (empty($edit['access']) && empty($account->access) && user_access('administer users')) {
$edit['access'] = REQUEST_TIME; $edit['access'] = REQUEST_TIME;
} }
// Find the fields attached to this user.
$field_names = array();
list(, , $bundle) = entity_extract_ids('user', (object) $edit);
foreach (field_info_instances('user', $bundle) as $instance) {
$field = field_info_field_by_id($instance['field_id']);
$field_names[] = $field['field_name'];
}
foreach ($edit as $key => $value) { foreach ($edit as $key => $value) {
// Form fields that don't pertain to the users, user_roles, or // Form fields that don't pertain to the users, user_roles, or
// Field API are automatically serialized into the users.data // Field API are automatically serialized into the users.data
// column. // column.
if (!in_array($key, array('roles', 'is_new')) && empty($user_fields[$key]) && empty($field_form[$key])) { if (!in_array($key, array('roles', 'is_new')) && empty($user_fields[$key]) && empty($field_names[$key])) {
if ($value === NULL) { if ($value === NULL) {
unset($data[$key]); unset($data[$key]);
} }
......
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