Performance fix for alternate getActivity listing function
authoreileen <emcnaughton@wikimedia.org>
Mon, 4 Feb 2019 00:10:44 +0000 (13:10 +1300)
committereileen <emcnaughton@wikimedia.org>
Mon, 4 Feb 2019 00:11:54 +0000 (13:11 +1300)
commit734f268381c93b2983f6afd2c268cc7cdae37815
treec68760e80426581d7afc4da14de46414410e35fe
parentf8f3fe349bfe1e5f7fdb1b5f4a53e12145dd229e
Performance fix for alternate getActivity listing function

We have an alternate function to render the activiy listing on the contact tab. It is
getActivities whereas the other is deprecatedGetActivities.

It was developed in order to replace the other and we have tests that compare the results of the 2. It is better in that it
1) performs better (on a  WMF contact with many activities this is 'snappy' while the current deprecated one gives a  white screen time out) and
2) calls the selectWhereClause hook, allowing hook alteration and respecting preferred architecture.

However, we didn't go live with it in core because it
1) has a remnant performance bugs (this PR fixes the last of these)
2) implements ACLs differently - it uses generic functions whereas the deprecated one
applies more limited permissioning. This is something to clarify & resolve separately.

This PR fixes the last remaining performance issue - best described as
'When one of the activities to be displayed has many targets the activity listing is slow to load'

The reason for the slowness is that when 'target_contact_name' is passed to the api
the api does a call for each contact to fetch the contact's sort_name. For a bulk mailing that went to 50,000 people that equates to 50,000 extra queries.

However the actual display shows the first contact name and then gives a number for how many more should be retrieved. This PR hence does not ask the api for the display name, but rather does the check itself, but
only for 1 target contact rather than ALL

Note that a similar logic might be considered for assignee - I left that out of scope as I'm not
aware of situations where a large number of assignees would be assigned to a single activity.

The unit test ensures the output matches the deprecated function.
CRM/Activity/BAO/Activity.php
tests/phpunit/CRM/Activity/BAO/ActivityTest.php