From 9254ec4e1f434312f9e0dd7f0f1711825f079270 Mon Sep 17 00:00:00 2001 From: CiviCRM Date: Wed, 9 Jul 2014 12:38:17 +0530 Subject: [PATCH] CRM-14670 : load only one target record per activity in temp table --- CRM/Activity/BAO/Activity.php | 39 ++++++++++++++--------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/CRM/Activity/BAO/Activity.php b/CRM/Activity/BAO/Activity.php index 6187167cde..53f9e19e2d 100644 --- a/CRM/Activity/BAO/Activity.php +++ b/CRM/Activity/BAO/Activity.php @@ -794,12 +794,13 @@ SELECT ac.activity_id, c.sort_name, c.is_deleted FROM {$activityTempTable} -INNER JOIN civicrm_activity a ON ( a.id = {$activityTempTable}.activity_id AND a.activity_type_id != {$bulkActivityTypeID} ) +INNER JOIN civicrm_activity a ON ( a.id = {$activityTempTable}.activity_id ) INNER JOIN civicrm_activity_contact ac ON ( ac.activity_id = {$activityTempTable}.activity_id ) INNER JOIN civicrm_contact c ON c.id = ac.contact_id - +WHERE ac.record_type_id != %1 "; - CRM_Core_DAO::executeQuery($query); + $params = array(1 => array($targetID, 'Integer')); + CRM_Core_DAO::executeQuery($query, $params); // for each activity insert one target contact // if we load all target contacts the performance will suffer a lot for mass-activities; @@ -812,13 +813,13 @@ SELECT ac.activity_id, c.is_deleted, count(ac.contact_id) FROM {$activityTempTable} -INNER JOIN civicrm_activity a ON ( a.id = {$activityTempTable}.activity_id AND a.activity_type_id = {$bulkActivityTypeID} ) +INNER JOIN civicrm_activity a ON ( a.id = {$activityTempTable}.activity_id ) INNER JOIN civicrm_activity_contact ac ON ( ac.activity_id = {$activityTempTable}.activity_id ) INNER JOIN civicrm_contact c ON c.id = ac.contact_id WHERE ac.record_type_id = %1 GROUP BY ac.activity_id "; - $params = array(1 => array($targetID, 'Integer')); + CRM_Core_DAO::executeQuery($query, $params); // step 3: Combine all temp tables to get final query for activity selector @@ -869,6 +870,7 @@ ORDER BY fixed_sort_order if (empty($values[$activityID]['target_contact_name'])) { $values[$activityID]['target_contact_name'] = array(); + $values[$activityID]['target_contact_counter'] = $dao->counter; } // if deleted, wrap in @@ -2513,28 +2515,19 @@ INNER JOIN civicrm_option_group grp ON ( grp.id = val.option_group_id AND grp.n elseif (!empty($values['recipients'])) { $contactActivities[$activityId]['target_contact'] = $values['recipients']; } - elseif (!$values['target_contact_name']) { - $contactActivities[$activityId]['target_contact'] = 'n/a'; - } - elseif (!empty($values['target_contact_name'])) { - $count = 0; - $contactActivities[$activityId]['target_contact'] = ''; + elseif (isset($values['target_contact_counter']) && $values['target_contact_counter']) { foreach ($values['target_contact_name'] as $tcID => $tcName) { - if ($tcID && $count < 5) { - $contactActivities[$activityId]['target_contact'] .= CRM_Utils_System::href($tcName, - 'civicrm/contact/view', "reset=1&cid={$tcID}"); - $count++; - if ($count) { - $contactActivities[$activityId]['target_contact'] .= "; "; - } + $contactActivities[$activityId]['target_contact'] .= CRM_Utils_System::href($tcName, + 'civicrm/contact/view', "reset=1&cid={$tcID}"); + } - if ($count == 4) { - $contactActivities[$activityId]['target_contact'] .= "(" . ts('more') . ")"; - break; - } - } + if ($extraCount = $values['target_contact_counter'] - 1) { + $contactActivities[$activityId]['target_contact'] .= ";
" . "(" . ts('%1 more', array(1 => $extraCount)) . ")"; } } + elseif (!$values['target_contact_name']) { + $contactActivities[$activityId]['target_contact'] = 'n/a'; + } if (empty($values['assignee_contact_name'])) { $contactActivities[$activityId]['assignee_contact'] = 'n/a'; -- 2.25.1