Skip to content

Commit

Permalink
Fix (sometimes serious) performance problem on submitting profiles fo…
Browse files Browse the repository at this point in the history
…r specified contacts.

->_id is set when the contact id is known - e.g in edit, in contactlayouteditor profile
blocks. However, current logic still retrieves duplicates and then... does nothing
with them if ->_id is set. By moving the if up higher we can save the server from
doing unnecesary queries. Note that if you submit a tag profile with no other fields in it
the query is server-destroyingly bad with this
  • Loading branch information
eileenmcnaughton committed Feb 15, 2019
1 parent 60f635a commit 6bbc85c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions CRM/Profile/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,7 @@ protected static function handleDuplicateChecking(&$errors, $fields, $form) {
CRM_Core_Session::setStatus(ts('Note: this contact may be a duplicate of an existing record.'), ts('Possible Duplicate Detected'), 'alert');
}
elseif ($form->_isUpdateDupe == 1) {
if (!$form->_id) {
$form->_id = $ids[0];
}
$form->_id = $ids[0];
}
else {
if ($form->_context == 'dialog') {
Expand Down Expand Up @@ -1003,6 +1001,8 @@ public static function formRule($fields, $files, $form) {

// hack we use a -1 in options to indicate that its registration
if ($form->_id) {
// @todo - wonder if it ever occurred to someone that if they didn't document this param
// it might not be crystal clear why we have it....
$form->_isUpdateDupe = 1;
}

Expand All @@ -1022,7 +1022,9 @@ public static function formRule($fields, $files, $form) {
$fields['phone-Primary'] = $fields['phone-Primary-1'];
}

self::handleDuplicateChecking($errors, $fields, $form);
if (!$form->_id) {
self::handleDuplicateChecking($errors, $fields, $form);
}
}

foreach ($fields as $key => $value) {
Expand Down

0 comments on commit 6bbc85c

Please sign in to comment.