Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-21111 Refactor include/exclude activity types into it's own function and im… #10909

Conversation

mattwire
Copy link
Contributor

@mattwire mattwire commented Aug 28, 2017

…prove performance (don't retrieve excluded activity types)

Before

API retrieved all activities, excluded activity types were removed afterwards.

After

API doesn't retrieve excluded activity types.

Technical Details

Extract activity type filtering to a new function filterActivityTypes();

Comments

The getActivities function is not actually in use anywhere yet so should be a relatively safe merge.

@mattwire mattwire force-pushed the CRM-21111_BAO_Activity_getActivities_cleanup branch from 30f54e9 to ebf3dd1 Compare August 28, 2017 17:28
@totten totten added the master label Aug 30, 2017
@mattwire mattwire force-pushed the CRM-21111_BAO_Activity_getActivities_cleanup branch from ebf3dd1 to fa4acd0 Compare March 16, 2018 16:58
@mattwire
Copy link
Contributor Author

test this please

}
elseif (!empty($activityTypes) && count($activityTypes)) {
$activityParams['activity_type_id'] = array('IN' => array_keys($activityTypes));
if ($params['context'] != 'activity') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure where $params['context'] came in from - original line is

-    if (!empty($params['activity_status_id'])) {
-      $activityParams['activity_status_id'] = array('IN' => explode(',', $params['activity_status_id']));
-    }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I'm not sure either. I've changed it back to the original.

@@ -840,10 +808,10 @@ public static function getActivities($params, $getCount = FALSE) {
else {
$activities[$id][$expectedName] = CRM_Utils_Array::value($apiKey, $activity);
if ($apiKey == 'activity_type_id') {
$activities[$id]['activity_type'] = CRM_Utils_Array::value($activities[$id][$expectedName], $activityTypes);
$activities[$id]['activity_type'] = CRM_Core_PseudoConstant::getName(__CLASS__, 'activity_type_id', $activities[$id][$expectedName]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to put in the class name in case the function ever gets moved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, changed all instances

}
elseif ($apiKey == 'campaign_id') {
$activities[$id]['campaign'] = CRM_Utils_Array::value($activities[$id][$expectedName], $allCampaigns);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually feel a bit nervous about this line - as an unrelated change I feel like I have to work quite hard to validate it or let it skate through (& the latter is not good)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, changed back to original.

if (!empty($activityTypes) && count($activityTypes)) {
return array('IN' => array_keys($activityTypes));
}
return NULL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this would only be hit if there were NO enabled activity types configured for the site at all? (in which case only inactive ones would be displayed)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty unlikely to hit NULL yes. As the return parameter is used as an API parameter it would return no activity types.


// If no activity types are specified or excluded, return the list of all active ones
if (empty($params['activity_type_id']) && empty($params['activity_type_exclude_id'])) {
if (!empty($activityTypes) && count($activityTypes)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think !empty is enough without count

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@eileenmcnaughton
Copy link
Contributor

@mattwire I took a look at this & I get what you are doing and I think it makes sense. I checked and this function has heavy test coverage - in fact it is currently ONLY reachable from the unit tests. The function has / had performance issues so we switched back to the deprecated function.

Given the above I'm happy to merge this if you can respond to the in-line comments. At least we will be in a better place if we later re-enable

Copy link
Contributor Author

@mattwire mattwire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eileenmcnaughton Let me know if you are happy with the changes and I'll squash the commits

if (!empty($activityTypes) && count($activityTypes)) {
return array('IN' => array_keys($activityTypes));
}
return NULL;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty unlikely to hit NULL yes. As the return parameter is used as an API parameter it would return no activity types.


// If no activity types are specified or excluded, return the list of all active ones
if (empty($params['activity_type_id']) && empty($params['activity_type_exclude_id'])) {
if (!empty($activityTypes) && count($activityTypes)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

}
elseif ($apiKey == 'campaign_id') {
$activities[$id]['campaign'] = CRM_Utils_Array::value($activities[$id][$expectedName], $allCampaigns);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, changed back to original.

@@ -840,10 +808,10 @@ public static function getActivities($params, $getCount = FALSE) {
else {
$activities[$id][$expectedName] = CRM_Utils_Array::value($apiKey, $activity);
if ($apiKey == 'activity_type_id') {
$activities[$id]['activity_type'] = CRM_Utils_Array::value($activities[$id][$expectedName], $activityTypes);
$activities[$id]['activity_type'] = CRM_Core_PseudoConstant::getName(__CLASS__, 'activity_type_id', $activities[$id][$expectedName]);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, changed all instances

}
elseif (!empty($activityTypes) && count($activityTypes)) {
$activityParams['activity_type_id'] = array('IN' => array_keys($activityTypes));
if ($params['context'] != 'activity') {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I'm not sure either. I've changed it back to the original.

@mattwire mattwire force-pushed the CRM-21111_BAO_Activity_getActivities_cleanup branch from fa4acd0 to cddf679 Compare May 27, 2018 14:30
@eileenmcnaughton
Copy link
Contributor

@mattwire sure - please squash & cheer up jenkins re e-notice & we can merge

…prove performance (don't retrieve excluded activity types)
@mattwire mattwire force-pushed the CRM-21111_BAO_Activity_getActivities_cleanup branch from cddf679 to 5b22d1b Compare May 28, 2018 21:22
@mattwire
Copy link
Contributor Author

@eileenmcnaughton Squashed, pending tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants