From 34cb437dfa8a5006ffb632cd9c2264c58781a6a9 Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 25 Jul 2018 14:47:20 +1200 Subject: [PATCH] Activity tab performance - switch from deprecatedGetActivitiesCount to getActivitiesCount ditto for getActivities. This is a combination of 2 upstream PRs https://github.com/civicrm/civicrm-core/pull/12557 and https://github.com/civicrm/civicrm-core/pull/12559 Note - when trying to test use contact 72 - pretty sure at the moment the new code is on staging & old on live Bug: T199753 Bug: T191867 Change-Id: I1624b70eca431c018727618ebc7e8c35dc2121d4 --- CRM/Activity/BAO/Activity.php | 32 +++++++++++++++--------------- CRM/Activity/Selector/Activity.php | 4 ++-- CRM/Contact/BAO/Contact.php | 2 +- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/CRM/Activity/BAO/Activity.php b/CRM/Activity/BAO/Activity.php index 31c3c253d932..68fc69e19caa 100644 --- a/CRM/Activity/BAO/Activity.php +++ b/CRM/Activity/BAO/Activity.php @@ -780,7 +780,7 @@ public static function getActivities($params, $getCount = FALSE) { continue; } - $isBulkActivity = (!$bulkActivityTypeID || ($bulkActivityTypeID != $activity['activity_type_id'])); + $isBulkActivity = (!$bulkActivityTypeID || ($bulkActivityTypeID === $activity['activity_type_id'])); foreach ($mappingParams as $apiKey => $expectedName) { if (in_array($apiKey, array('assignee_contact_name', 'target_contact_name'))) { $activities[$id][$expectedName] = CRM_Utils_Array::value($apiKey, $activity, array()); @@ -2862,10 +2862,10 @@ public static function getContactActivitySelector(&$params) { } // Get contact activities. - $activities = CRM_Activity_BAO_Activity::deprecatedGetActivities($params); + $activities = CRM_Activity_BAO_Activity::getActivities($params); // Add total. - $params['total'] = CRM_Activity_BAO_Activity::deprecatedGetActivitiesCount($params); + $params['total'] = CRM_Activity_BAO_Activity::getActivitiesCount($params); // Format params and add links. $contactActivities = array(); @@ -2932,19 +2932,19 @@ public static function getContactActivitySelector(&$params) { } elseif (isset($values['target_contact_counter']) && $values['target_contact_counter']) { $activity['target_contact_name'] = ''; - foreach ($values['target_contact_name'] as $tcID => $tcName) { - $targetTypeImage = ""; - $targetLink = CRM_Utils_System::href($tcName, 'civicrm/contact/view', "reset=1&cid={$tcID}"); - if ($showContactOverlay) { - $targetTypeImage = CRM_Contact_BAO_Contact_Utils::getImage( - CRM_Contact_BAO_Contact::getContactType($tcID), - FALSE, - $tcID); - $activity['target_contact_name'] .= "
$targetTypeImage $targetLink"; - } - else { - $activity['target_contact_name'] .= $targetLink; - } + $firstTargetName = reset($values['target_contact_name']); + $firstTargetContactID = key($values['target_contact_name']); + + $targetLink = CRM_Utils_System::href($firstTargetName, 'civicrm/contact/view', "reset=1&cid={$firstTargetContactID}"); + if ($showContactOverlay) { + $targetTypeImage = CRM_Contact_BAO_Contact_Utils::getImage( + CRM_Contact_BAO_Contact::getContactType($firstTargetContactID), + FALSE, + $firstTargetContactID); + $activity['target_contact_name'] .= "
$targetTypeImage $targetLink"; + } + else { + $activity['target_contact_name'] .= $targetLink; } if ($extraCount = $values['target_contact_counter'] - 1) { diff --git a/CRM/Activity/Selector/Activity.php b/CRM/Activity/Selector/Activity.php index e7f2541bed8e..d9862c925767 100644 --- a/CRM/Activity/Selector/Activity.php +++ b/CRM/Activity/Selector/Activity.php @@ -352,7 +352,7 @@ public function getTotalCount($action, $case = NULL) { 'rowCount' => 0, 'sort' => NULL, ); - return CRM_Activity_BAO_Activity::deprecatedGetActivitiesCount($params); + return CRM_Activity_BAO_Activity::getActivitiesCount($params); } /** @@ -386,7 +386,7 @@ public function &getRows($action, $offset, $rowCount, $sort, $output = NULL, $ca 'sort' => $sort, ); $config = CRM_Core_Config::singleton(); - $rows = CRM_Activity_BAO_Activity::deprecatedGetActivities($params); + $rows = CRM_Activity_BAO_Activity::getActivities($params); if (empty($rows)) { return $rows; diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index f222e19594a8..e1c22d2cc703 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -2727,7 +2727,7 @@ public static function getCountComponent($component, $contactId, $tableName = NU 'caseId' => NULL, 'context' => 'activity', ); - return CRM_Activity_BAO_Activity::deprecatedGetActivitiesCount($input); + return CRM_Activity_BAO_Activity::getActivitiesCount($input); case 'mailing': $params = array('contact_id' => $contactId);