CRM-20594: Optimze Counting of Reltionships on Contact Summary
authorCamilo Rodriguez <camilo@compucorp.co.uk>
Wed, 17 May 2017 16:00:47 +0000 (16:00 +0000)
committerCamilo Rodriguez <camilo@compucorp.co.uk>
Wed, 17 May 2017 16:00:47 +0000 (16:00 +0000)
commitb7d1995785815675558fbfe0a17373cb984b9c96
treee2153e7f064c39fbf0ddc24fdfd0f9470385f097
parentec64795ef1441149ea985daabe65f003ad6dde7c
CRM-20594: Optimze Counting of Reltionships on Contact Summary

Contacts with a lot of relationships (over 5000) were taking a lot of time to
load.  This was because the count of relationships was being done by fetching
ALL records of relationships associated to the contact, and then counting the
number of elements in the resulting array.

Fixed by changing the call to CRM_Contact_BAO_Relationship::getRelationship()
being used in CRM_Contact_BAO_Contact::getCountComponent(), passing the
$count parameter as 1 instead of 0, so counting is done by the database by
building a 'SELECT COUNT(*)' type of query.

Also, removed some unnecessary joins when counting records in DB, ie. when
$count flag is 1.
CRM/Contact/BAO/Contact.php [changed mode: 0644->0755]
CRM/Contact/BAO/Relationship.php [changed mode: 0644->0755]