From de8761eb2422762fa12c72cf504db79920497b59 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Mon, 22 Feb 2010 19:51:15 +0000 Subject: - Patch #721436 by chx, moshe weitzman: improved performance of user_save() by removing and reworking some code. --- modules/user/user.module | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'modules/user/user.module') diff --git a/modules/user/user.module b/modules/user/user.module index 6452c81d7..f99fe2ea9 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -360,16 +360,9 @@ function user_save($account, $edit = array(), $category = 'account') { unset($edit['pass']); } - // Get the fields form so we can recognize the fields in the $edit - // form that should not go into the serialized data array. - $field_form = array(); - $field_form_state = form_state_defaults(); + // Presave field allowing changing of $edit. $edit = (object) $edit; - field_attach_form('user', $edit, $field_form, $field_form_state); - - // Presave fields. field_attach_presave('user', $edit); - $edit = (array) $edit; if (!isset($account->is_new)) { @@ -385,11 +378,19 @@ function user_save($account, $edit = array(), $category = 'account') { if (empty($edit['access']) && empty($account->access) && user_access('administer users')) { $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) { // Form fields that don't pertain to the users, user_roles, or // Field API are automatically serialized into the users.data // 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) { unset($data[$key]); } -- cgit v1.2.3